FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Easy

Object Map

10mins

Implement a function objectMap(obj, iteratee) that transforms the values of an object using the provided iteratee function.

The function should:

  • Accept an object and an iteratee function.
  • Apply the iteratee to each value in the object.
  • Return a new object with the same keys and transformed values.
  • Return an empty object if input is null or not an object.

Examples

objectMap({ a: 1, b: 2, c: 3 }, x => x * 2); // { a: 2, b: 4, c: 6 } objectMap({ name: "Alice", age: 25 }, v => String(v)); // { name: "Alice", age: "25" } objectMap({}, v => v); // {}

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests