function* range(start, stop) {
if (typeof stop !== 'number') {
stop = start;
start = 0;
}
let current = start;
while (current < stop) {
yield current;
current++;
}
}
function* generatorFilter(sequence, predicate) {
for (const element of sequence) {
if (predicate(element)) {
yield element;
}
}
}
function iteratorFilter(sequence, predicate) {
return {
[Symbol.iterator]() {
const itr = sequence[Symbol.iterator]();
return {
next() {
let current = itr.next();
while (!current.done &&
!predicate(current.value)) {
current = itr.next();
}
return current;
},
};
},
};
}
function filterCallback(sequence, predicate, callback) {
for (const e of sequence) {
if (predicate(e)) {
callback(e);
}
}
}
const data = Array.from(range(100000));
const isEven = (n) => n % 2 === 0;