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:
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.