partition splits an array into two groups: the elements that pass a predicate and the elements that fail it. It's filter that keeps both halves — the matches and the rejects — instead of throwing one away. Reach for it when you need "the active users and the inactive ones," not just one side.
Implement partition(arr, predicate, thisArg). Return a pair [pass, fail]: passing elements first, failing elements second, each in the original relative order. Do it in a single pass, calling the predicate once per element.
function partition(arr, predicate, thisArg) {
// returns [pass, fail]: [elements where predicate is truthy,
// elements where it is falsy]
}
partition([1, 2, 3, 4], (n) => n % 2 === 0); // [[2, 4], [1, 3]]
const [adults, minors] = partition(people, (p) => p.age >= 18);
partition([2, 4], (n) => n % 2 === 0); // [[2, 4], []] — all pass
[passing, failing], in that order.true.(value, index, array), with thisArg as this. Don't mutate the input; return two new arrays.