jsmodern
Version:
An extension to existing JavaScript, influenced by other great languages such as Rust, Dart, Java, Golang, etc.
17 lines • 489 B
JavaScript
export const retain = {
label: 'retain',
fn: function arrayRetain(predicate) {
const ctx = this;
if ('function' !== typeof (predicate)) {
throw new TypeError(`Expect 'predicate' to be a function`);
}
const len = ctx.length;
if (!len)
return;
const retained = ctx.filter(predicate);
ctx.length = 0;
for (const n of retained)
ctx.push(n);
},
};
//# sourceMappingURL=retain.js.map