Problem, as an interviewer would state it:
"Implement compact(array) — removing every FALSY value from the array, matching lodash's own well-known _.compact behavior."
Examples:
compact([0, 1, false, 2, "", 3]); // [1, 2, 3]
Clarifying questions expected:
- What is the real, complete, correct definition of "falsy" in JavaScript — every value that would evaluate as false in a boolean context?
- Does this need to preserve the relative order of the surviving truthy elements?
- Is this genuinely just a one-line filter, or is there a deeper real correctness concern worth discussing?
Code / implementation expected: Yes — real, direct proof against an array containing EVERY genuine JavaScript falsy value, confirming all are correctly removed while truthy order is preserved.