generated from rollup/rollup-starter-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
39 lines (32 loc) · 733 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class Iterator {
constructor(elements) {
this.elements = elements;
this.current = -1;
}
cycleBack() {
this.current = this.current === this.elements.length ? 0 : this.current;
this.current =
this.current < 0 ? this.elements.length - 1 : this.current;
}
next() {
this.current++;
this.cycleBack();
return {value: this.elements[this.current], done: false};
}
previous() {
this.current--;
this.cycleBack();
return {value: this.elements[this.current], done: false};
}
nextValue() {
return this.next().value;
}
previousValue() {
return this.previous().value;
}
}
function cartwheel(iterable) {
const elements = Array.from(iterable);
return new Iterator(elements);
}
export default cartwheel;