onix-core
Version:
Onix library core
21 lines • 624 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.grep = void 0;
const grep = (elems, callback, invert) => {
let callbackInverse;
let matches = [];
let i = 0;
const length = elems.length;
const callbackExpect = !invert;
// Go through the array, only saving the items
// that pass the validator function
for (; i < length; i++) {
callbackInverse = !callback(elems[i], i);
if (callbackInverse !== callbackExpect) {
matches.push(elems[i]);
}
}
return matches;
};
exports.grep = grep;
//# sourceMappingURL=Grep.js.map