jsmodern
Version:
An extension to existing JavaScript, influenced by other great languages such as Rust, Dart, Java, Golang, etc.
19 lines • 564 B
JavaScript
export const partition = {
label: 'partition',
fn: function arrayPartition(predicate) {
const ctx = this;
const len = ctx.length;
if ('function' !== typeof (predicate)) {
throw new TypeError(`Expect 'predicate' to be a function`);
}
if (!len)
return [[], []];
const matched = [];
const rest = [];
for (const n of ctx) {
predicate(n) ? matched.push(n) : rest.push(n);
}
return [matched, rest];
},
};
//# sourceMappingURL=partition.js.map