Skip to the solution
EasyDSAAsked in 20246 min read

Polyfill Object.fromEntries() — Handle Duplicate and Symbol Keys

761 views

The problem

Problem, as an interviewer would state it: "Implement Object.fromEntries from scratch — converting an iterable of [key, value] pairs back into a plain object, matching real native Object.fromEntries's own documented contract, including its real, defining relationship with Object.entries."

Examples:

Code
Object.fromEntries([["a", 1], ["b", 2]]); // {a: 1, b: 2}
Object.fromEntries(new Map([["x", 10]])); // {x: 10}

Clarifying questions expected:

  • When the SAME key appears in multiple entries, does the LAST occurrence genuinely win, matching a real, predictable overwrite order?
  • Does this need to accept any real iterable of pairs (a Map, a generator), not just a plain array of arrays?
  • Should a Symbol used as a key be correctly preserved, not silently dropped or stringified?

Code / implementation expected: Yes — real, direct proof against the ACTUAL native Object.fromEntries, including duplicate-key overwrite order, a real Symbol key, a real Map input, and a real round trip through Object.entries.

  • js-coding
  • utility
  • algorithm

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

6 min read · 9 sections

Run the code

Edit the code and run it here. Each console line with an expected value becomes a test.

JavaScriptReal, direct proof: the Object.fromEntries polyfill matches real native output, including duplicate-key overwrite order, a real symbol key, and a real Map input

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 31 of 154 in JavaScript coding

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

Up nextEasy

Unzip Array

Continue