3 ms·
const truthy = [], falsy = []; for (const i of values) { (i ? truthy : falsy).push(i); } If for some reason you did want to use reduce (and I see
by paulddraper 7y ago
const truthy = [], falsy = [];
for (const i of values) {
(i ? truthy : falsy).push(i);
}
If for some reason you did want to use reduce (and I see no reason to), it would be
const [truthy, falsey] = exampleValues.reduce((arrays, i) => {
arrays[+!i].push(i);
return arrays;
}, [[], []]);
- deleted 7y ago[deleted]