v1
- by eirikur 2/4/202400
Setup HTML - click to add setup HTML
disable setup JavaScript
Setup JavaScript
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;
delete caserun single casemove downdrag and drop case


ready



Array.from(generatorFilter(data, isEven));
delete caserun single casemove upmove downdrag and drop case


ready



Array.from(iteratorFilter(data, isEven));
delete caserun single casemove upmove downdrag and drop case


ready



const results = [];
filterCallback(data, isEven, e => results.push(e));
delete caserun single casemove updrag and drop case


ready



data.filter(isEven);
Test Case - click to add another test case
Teardown JS - click to add teardown JavaScript
Output (DOM) - click to monitor output (DOM) while test is running
RUN