-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroiterator.js
More file actions
44 lines (33 loc) · 792 Bytes
/
roiterator.js
File metadata and controls
44 lines (33 loc) · 792 Bytes
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
40
41
42
43
44
'use strict';
function Iterator(array, startIndex) {
/* jshint maxstatements: 10 */
var index = startIndex || 0;
this.val = function () {
return array[index];
};
this.hasPrev = function () {
return index > 0;
};
this.prev = function () {
return new Iterator (array, index - 1);
};
this.hasNext = function () {
return index < array.length - 1;
};
this.next = function () {
return new Iterator (array, index + 1);
};
this.arr = function () {
return array;
};
this.index = function () {
return index;
};
this.isValid = function () {
return index >= 0 && index < array.length;
};
}
module.exports = Iterator;
module.exports.atEnd = function (array) {
return new Iterator(array, array.length - 1);
};