Problem, as an interviewer would state it:
"Implement difference(a, b) — returning every element of a that does NOT appear anywhere in b, preserving a's own original relative order, matching lodash's own well-known _.difference behavior."
Examples:
difference([1,2,3,4], [2,4]); // [1,3]
Clarifying questions expected:
- Is this a genuinely ASYMMETRIC operation — elements in
abut notb, as opposed to a full, symmetric set difference (in either but not both)? - Should the result preserve
a's own original relative order? - What real, efficient lookup structure should be used to check membership in
b, avoiding a naive nested-loop approach?
Code / implementation expected: Yes — real, direct proof of basic asymmetric difference, confirmation a's own order is preserved, and confirmation of the correct, real "b contains everything" edge case.