Implement conformsTo
A shape-validator: for every predicate in `source`, run it against the matching value in `object` and require all of them to pass. `Array.prototype.every` does the actual checking in one line — the only real decision is what to do when there's nothing to check at all.
The problem
Implement `conformsTo(object, source)` returning whether every own property of `source` is a predicate that returns truthy when called with the corresponding value from `object` — `conformsTo({ a: 1, b: 2 }, { b: (n) => n > 1 })` → `true`, `{ b: (n) => n > 2 }` → `false`.
The spec calls out one specific rule: an empty `object` must make the function return `false`, even in cases the general predicate-checking logic wouldn't otherwise catch — `conformsTo({}, {})` has no predicates to fail, but the empty `object` still has to force `false`.
The approach
The core check is `Object.keys(source).every((key) => source[key](object[key]))` — for each predicate key, call it with the value at that key on `object`, and require every call to return truthy. `.every` short-circuits on the first failure, so a bad key is found without checking the rest.
That alone already handles `conformsTo({}, { b: (n) => n > 1 })` correctly, since `object.b` is `undefined` and the predicate `n > 1` fails on it. What it doesn't handle is `source` having zero predicate keys: `Object.keys({}).every(...)` is vacuously `true` on an empty array, which would incorrectly report an empty `object` as conforming to an empty `source`.
Guarding with `if (Object.keys(object).length === 0) return false` before the `every` check closes that gap — an empty `object` never conforms, regardless of what (or how little) `source` asks of it.
The solution
/**
* @param {Object} object The object to inspect.
* @param {Object} source The object of property predicates to conform to.
* @returns {boolean} Returns true if object conforms, else false.
*/
export default function conformsTo(object, source) {
if (Object.keys(object).length === 0) return false;
return Object.keys(source).every((key) => source[key](object[key]));
}Time O(k)Space O(k)