typescript split/partition array by condition code example
Example: typescript split/partition array by condition
const [small, large] = // Use "deconstruction" style assignment
[12, 5, 8, 130, 44]
.reduce((result, element) => {
result[element <= 10 ? 0 : 1].push(element); // Determine and push to small/large arr
return result;
},
[[], []]); // Default small/large arrays are empty