function* range(start, end) {
while (start < end) {
yield start++;
}
}
function* evens(iter) {
for (const val of iter) {
if (val % 2 === 0) yield val;
}
}
function* take(n, iter) {
let count = 0;
for (const val of iter) {
if (count++ >= n) return;
yield val;
}
}
function* pipeline() {
yield* take(3, evens(range(1, 20)));
yield* take(2, range(10, 15));
}
const result = [...pipeline()];
console.log(result);
Ответ: [2, 4, 6, 10, 11]
JavaScript test | #JavaScript & Max