Problem, as an interviewer would state it: "Split an array into two lists: one with the elements that satisfy a predicate and one with those that do not. Support asynchronous predicates."
Examples:
partition([1, 2, 3, 4, 5, 6], n => n % 2 === 0); // [[2, 4, 6], [1, 3, 5]]
await partitionAsync(users, u => isActive(u.id)); // [[active...], [inactive...]]
Clarifying questions expected:
- Must the original order be preserved inside each group?
- For an async predicate, should the checks run in parallel or one at a time, and what happens if one rejects?
- Is it acceptable to call the predicate twice per element (for example by filtering twice)?
Code / implementation expected: Yes — real, direct proof for both versions, including the out-of-order-completion and rejection cases.