FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Medium

Use Map

20mins

Implement a hook useMap(initialMap) that provides a reactive Map-like object with utility functions.

The hook should:

  • Accept an optional initial object to populate the map.
  • Provide methods to get, set, delete, has, clear keys.
  • Provide a method values() or entries() to get all current entries.
  • Updates to the map should be reflected immediately when accessed through these methods.

Example

const map = useMap({ a: 1, b: 2 }); map.set("c", 3); map.get("a"); // 1 map.delete("b"); map.has("b"); // false

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests