Skip to content

Instantly share code, notes, and snippets.

@bassettsj
Last active May 13, 2021 23:49
Show Gist options
  • Save bassettsj/9c35eec3405f837419b70526fdbdc4ed to your computer and use it in GitHub Desktop.
Save bassettsj/9c35eec3405f837419b70526fdbdc4ed to your computer and use it in GitHub Desktop.
const test = require('tape');
class Iterator {
hasNext() {
// Your code here
}
next() {
// Your code here
}
}
const exampleOne = new Iterator([[1, 2, 3], [], [4, 5, 6]]);
const exampleTwo = new Iterator([[], []]);
const exampleThree = new Iterator([[], [1]]);
test('hasNext()', (t) => {
t.plan(3);
t.equal(exampleOne.hasNext(), true);
t.equal(exampleTwo.hasNext(), false);
t.equal(exampleThree.hasNext(), true);
});
test('next()', (t) => {
t.plan(9);
t.equal(exampleOne.next(), 1);
t.equal(exampleOne.next(), 2);
t.equal(exampleOne.next(), 3);
t.equal(exampleOne.next(), 4);
t.equal(exampleOne.next(), 5);
t.equal(exampleOne.next(), 6);
t.equal(exampleOne.next(), null);
t.equal(exampleTwo.next(), null);
t.equal(exampleThree.hasNext(), true);
t.equal(exmapleThree.next(), 1);
t.equal(exampleThree.hasNext(), false);
t.equal(exmapleThree.next(), null);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment