Problem, as an interviewer would state it:
"Implement groupBy(array, iteratee) — grouping array elements into an object keyed by the result of calling iteratee on each element, matching lodash's own well-known _.groupBy behavior."
Examples:
groupBy([1,2,3,4,5,6], n => n % 2 === 0 ? "even" : "odd");
// { odd: [1,3,5], even: [2,4,6] }
Clarifying questions expected:
- Should the iteratee support both a real function AND a plain string shortcut (grouping by that property name directly), matching lodash's own dual-input convention?
- What real, correct order should elements appear in WITHIN each group?
- What should happen if the iteratee genuinely returns a non-string value, like a number or an object?
Code / implementation expected: Yes — real, direct proof with both a function iteratee and a string-property iteratee, confirming correct grouping and preserved insertion order within each group.