#
Size: a a a
#
ꟿ
ꟿ
#
#
ꟿ
NN
const arr = Array.from({ length: 400 }, () => ~~(Math.random() * 40));
let t1 = performance.now();
const res = arr.filter(el => el == 2);
let t2 = performance.now();
console.log('Filter', t2 - t1, res);
t1 = performance.now();
let res2 = (function(fn, a) {
const f = []; //final
for (let i = 0; i < a.length; i++) {
if (fn(a[i])) {
f.push(a[i]);
}
}
return f;
})(el => el == 2, arr);
t2 = performance.now();
console.log('Fn', t2 - t1, res2);
ꟿ
ꟿ
NN
NN
#
#
NN
NN
AM
fetch() {
const result = [];
while (true) {
for (let j = 0; j < this.filters.length; j++) {
const filter = this.filters[j];
for (let i = 0; i < filter.cnt; i++) {
const splicedIndex = this.stack.findIndex(filter.filter);
if (splicedIndex === -1) {
return result;
}
result.push(...this.stack.splice(splicedIndex, 1));
}
}
}
}
NN
#
E
#