assertEquals('c', iter.next());
assertFalse(iter.hasNext());
assertNull(iter.next());
-}
\ No newline at end of file
+}
+
+UtilsTestCase.prototype.testIterator_no_args = function() {
+ var array = ['a', 'b', 'c'];
+ var iter = Dygraph.createIterator(array);
+ assertTrue(iter.hasNext());
+ assertEquals('a', iter.next());
+ assertTrue(iter.hasNext());
+ assertEquals('b', iter.next());
+ assertTrue(iter.hasNext());
+ assertEquals('c', iter.next());
+ assertFalse(iter.hasNext());
+ assertNull(iter.next());
+}
* @param predicate a function that takes parameters array and idx, which
* returns true when the element should be returned. If omitted, all
* elements are accepted.
- *
- * TODO(konigsberg): add default vlues to start and length.
*/
Dygraph.createIterator = function(array, start, length, predicate) {
+ start = start || 0;
+ length = length || array.length;
var iter = new function() {
this.end_ = Math.min(array.length, start + length);
this.nextIdx_ = start - 1; // use -1 so initial call to advance works.