FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Medium

Conforms To

20mins

Implement a function conformsTo(obj, source) that checks if the given object satisfies the conditions defined in the source object.

The function should:

  • Return true if for every key in source, the corresponding value in obj passes the predicate function in source.
  • Return false otherwise.
  • If a key in source does not exist in obj, treat it as failing the predicate.

Example

const obj = { a: 5, b: 10 }; const source = { a: x => x > 0, b: y => y < 20 }; conformsTo(obj, source); // true const source2 = { a: x => x < 0 }; conformsTo(obj, source2); // false

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests