From 648855397d1696b840865ad97b9b895558b4e0dc Mon Sep 17 00:00:00 2001 From: Robert Konigsberg Date: Mon, 18 Jun 2012 15:10:20 -0400 Subject: [PATCH] Add default values to the iterator factory. --- auto_tests/tests/utils_test.js | 15 ++++++++++++++- dygraph-utils.js | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/auto_tests/tests/utils_test.js b/auto_tests/tests/utils_test.js index 05f7169..9c8974c 100644 --- a/auto_tests/tests/utils_test.js +++ b/auto_tests/tests/utils_test.js @@ -156,4 +156,17 @@ UtilsTestCase.prototype.testIterator_whole_array = function() { 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()); +} diff --git a/dygraph-utils.js b/dygraph-utils.js index 907069f..9d599f3 100644 --- a/dygraph-utils.js +++ b/dygraph-utils.js @@ -695,10 +695,10 @@ Dygraph.isAndroid = function() { * @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. -- 2.7.4