JSFiddle - React, Tailwind, and code Playground
by Thomas Upton
HTML
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js"></script>
JavaScript
const l = ['even', 'odd', 'even2', 'odd2', 'even3'];
const partition = (collection, predicate) => _.reduce(collection, ([truthy, falsy], value, index, coll) =>
predicate(value, index, collection) ? [[...truthy, value], falsy] : [truthy, [...falsy, value]], [[], []]);
const p = partition(l, (v, i, c) => {
console.log(v, i, c);
return i % 2 === 0;
});
console.log(p);