Challenge 1
Create the iterator returned by Symbol.iterator.
const iterable = {
values: [10, 20],
[Symbol.iterator]() {
return ;
}
};
Press Ctrl⌘Enter to check your answer
Practice the iterable protocol, generator control flow, delegation, and lazy iterator helpers.
Challenge 1
const iterable = {
values: [10, 20],
[Symbol.iterator]() {
return ;
}
};
Press Ctrl⌘Enter to check your answer
Challenge 2
function* values() {
yield 2;
}
Press Ctrl⌘Enter to check your answer
Challenge 3
function* ask() {
const answer = yield "question";
return answer;
}
const it = ask();
it.next();
const result = it.;
Press Ctrl⌘Enter to check your answer
Challenge 4
function* values() {
yield "start";
[1, 2];
}
Press Ctrl⌘Enter to check your answer
Challenge 5
const result = Iterator.from([1, 2, 3]).(2).toArray();
Press Ctrl⌘Enter to check your answer
Challenge 6
const result = Iterator.from([1, 2, 3]).(value => value * 2).toArray();
Press Ctrl⌘Enter to check your answer
Challenge 7
const result = Iterator.from([1, 2, 3, 4]).(value => value % 2 === 0).toArray();
Press Ctrl⌘Enter to check your answer
Challenge 8
const iterator = (new Set([1, 2, 3]));
Press Ctrl⌘Enter to check your answer
Challenge 9
const pairs = Iterator.zip([[1, 2], ["a", "b"]]);
const result = pairs.;
Press Ctrl⌘Enter to check your answer
Challenge 10
const result = Iterator.zip([[1, 2], ["a", "b"]], { mode: }).toArray();
Press Ctrl⌘Enter to check your answer
Challenge 11
const rows = Iterator.zipKeyed({ name: ["Ada"], score: [10] }).;
Press Ctrl⌘Enter to check your answer
Challenge 12
const iterator = [1, 2][Symbol.iterator]();
iterator.next();
iterator.;
Press Ctrl⌘Enter to check your answer