From: Robert Konigsberg Date: Mon, 18 Jun 2012 19:10:20 +0000 (-0400) Subject: Add default values to the iterator factory. X-Git-Tag: v1.0.0~238^2^2~4 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=648855397d1696b840865ad97b9b895558b4e0dc;p=dygraphs.git Add default values to the iterator factory. --- 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.