# robspassky/underscore forked from jashkenas/underscore

0.4.6 is on the books, with kylichuku's range function

jashkenas committed Dec 1, 2009
Showing with 81 additions and 50 deletions.
1. +34 −3 index.html
2. +11 −0 test/arrays.js
3. +0 −15 test/generators.js
4. +4 −0 test/speed.js
5. +0 −1 test/test.html
6. +15 −2 underscore-min.js
7. +17 −29 underscore.js
 @@ -107,11 +107,11 @@

Development Version (0.4.5)Development Version (0.4.6) 18kb, Uncompressed with Comments
Production Version (0.4.5)Production Version (0.4.6) 2kb, Packed and Gzipped
- + - + @@ -186,7 +186,7 @@

first, rest, last, compact, flatten, without, uniq, intersect, zip, indexOf, - lastIndexOf + lastIndexOf, range

@@ -583,6 +583,28 @@

Array Functions

_.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
=> 4
+
+ +

+ range_.range([start], stop, [step]) +
+ A function to create flexibly-numbered lists of integers, handy for + each and map loops. start, if omitted, defaults + to 0; step defaults to 1. Returns a list of integers + from start to stop, incremented (or decremented) by step, + exclusive. +

+
+_.range(10);
+=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+_.range(1, 11);
+=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+_.range(0, 30, 5);
+=> [0, 5, 10, 15, 20, 25]
+_.range(0, -10, -1);
+=> [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
+_.range(0);
+=> []

Function (uh, ahem) Functions

@@ -930,6 +952,15 @@

Chaining

Change Log

+

+ 0.4.6
+ Added the range function, a port of the + Python + function of the same name, for generating flexibly-numbered lists + of integers. Original patch contributed by + Kirill Ishanov. +

+

0.4.5
Added rest for Arrays and arguments objects, and aliased

 @@ -86,4 +86,15 @@ \$(document).ready(function() { equals(result, 5, 'works on an arguments object'); }); + test("arrays: range", function() { + equals(_.range(0).join(''), '', 'range with 0 as a first argument generates an empty array'); + equals(_.range(4).join(' '), '0 1 2 3', 'range with a single positive argument generates an array of elements 0,1,2,...,n-1'); + equals(_.range(5, 8).join(' '), '5 6 7', 'range with two arguments a & b, a b-a, a < b generates an array with a single element, equal to a'); + equals(_.range(12, 7, -2).join(' '), '12 10 8', 'range with three arguments a & b & c, a > b, c < 0 generates an array of elements a,a-c,a-2c and ends with the number not less than b'); + equals(_.range(0, -10, -1).join(' '), '0 -1 -2 -3 -4 -5 -6 -7 -8 -9', 'final example in the Python docs'); + }); + });
 @@ -1,15 +0,0 @@ -\$(document).ready(function() { - - module("Generator functions (range...)"); - - test("generators: range", function() { - equals(_.range(0).join(''), '', 'range with 0 as a first argument generates an empty array'); - equals(_.range(4).join(' '), '0 1 2 3', 'range with a single positive argument generates an array of elements 0,1,2,...,n-1'); - equals(_.range(5, 8).join(' '), '5 6 7', 'range with two arguments a & b, a b-a, a < b generates an array with a single element, equal to a'); - equals(_.range(12, 7, -2).join(' '), '12 10 8', 'range with three arguments a & b & c, a > b, c < 0 generates an array of elements a,a-c,a-2c and ends with the number not less than b'); - }); -}); -
 @@ -63,4 +63,8 @@ return _.intersect(numbers, randomized); }); + JSLitmus.test('_.range()', function() { + return _.range(1000); + }); + })();
 @@ -7,7 +7,6 @@ -