Problem, as an interviewer would state it:
"Implement dedupe(array) — removing every duplicate value while preserving the original, real first-occurrence order of each unique element."
Examples:
dedupe([3,1,2,3,1,4,2]); // [3,1,2,4]
Clarifying questions expected:
- Does the real ORDER of the surviving unique elements need to genuinely match their FIRST occurrence in the input, or is any order acceptable?
- What comparison algorithm should genuinely determine "duplicate" — should a real
NaNbe treated as a duplicate of anotherNaN? - Is a one-line
[...new Set(array)]an acceptable, real, idiomatic solution, or does the interviewer want the underlying mechanism demonstrated explicitly?
Code / implementation expected: Yes — real, direct proof of order preservation, plus a real, direct demonstration of the underlying comparison algorithm's edge cases (NaN, +0/-0).