Permalink
Browse files

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

  • Loading branch information...
jashkenas committed Dec 1, 2009
1 parent 64cac95 commit 4b2744a75adb3697ae2c99101704abdf512551dd
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
View
@@ -107,11 +107,11 @@ <h2>Downloads <i style="padding-left: 12px; font-size:12px;">(Right-click, and u
<p>
<table>
<tr>
- <td><a href="underscore.js">Development Version (0.4.5)</a></td>
+ <td><a href="underscore.js">Development Version (0.4.6)</a></td>
<td><i>18kb, Uncompressed with Comments</i></td>
</tr>
<tr>
- <td><a href="underscore-min.js">Production Version (0.4.5)</a></td>
+ <td><a href="underscore-min.js">Production Version (0.4.6)</a></td>
<td><i>2kb, Packed and Gzipped</i></td>
</tr>
</table>
@@ -186,7 +186,7 @@ <h2>Table of Contents</h2>
<span class="methods"><a href="#first">first</a>, <a href="#rest">rest</a>, <a href="#last">last</a>,
<a href="#compact">compact</a>, <a href="#flatten">flatten</a>, <a href="#without">without</a>, <a href="#uniq">uniq</a>,
<a href="#intersect">intersect</a>, <a href="#zip">zip</a>, <a href="#indexOf">indexOf</a></span>,
- <a href="#lastIndexOf">lastIndexOf</a></span>
+ <a href="#lastIndexOf">lastIndexOf</a>, <a href="#range">range</a></span>
</p>
<p>
@@ -583,6 +583,28 @@ <h2>Array Functions</h2>
<pre>
_.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
=&gt; 4
+</pre>
+
+ <p id="range">
+ <b class="header">range</b><code>_.range([start], stop, [step])</code>
+ <br />
+ A function to create flexibly-numbered lists of integers, handy for
+ <tt>each</tt> and <tt>map</tt> loops. <b>start</b>, if omitted, defaults
+ to <i>0</i>; <b>step</b> defaults to <i>1</i>. Returns a list of integers
+ from <b>start</b> to <b>stop</b>, incremented (or decremented) by <b>step</b>,
+ exclusive.
+ </p>
+ <pre>
+_.range(10);
+=&gt; [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+_.range(1, 11);
+=&gt; [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+_.range(0, 30, 5);
+=&gt; [0, 5, 10, 15, 20, 25]
+_.range(0, -10, -1);
+=&gt; [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
+_.range(0);
+=&gt; []
</pre>
<h2>Function (uh, ahem) Functions</h2>
@@ -930,6 +952,15 @@ <h2>Chaining</h2>
<h2>Change Log</h2>
+ <p>
+ <b class="header">0.4.6</b><br />
+ Added the <tt>range</tt> function, a port of the
+ <a href="http://docs.python.org/library/functions.html#range">Python
+ function of the same name</a>, for generating flexibly-numbered lists
+ of integers. Original patch contributed by
+ <a href="http://github.com/kylichuku">Kirill Ishanov</a>.
+ </p>
+
<p>
<b class="header">0.4.5</b><br />
Added <tt>rest</tt> for Arrays and arguments objects, and aliased
View
@@ -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 generates an array of elements a,a+1,a+2,...,b-2,b-1');
+ equals(_.range(8, 5).join(''), '', 'range with two arguments a & b, b<a generates an empty array');
+ equals(_.range(3, 10, 3).join(' '), '3 6 9', 'range with three arguments a & b & c, c < b-a, a < b generates an array of elements a,a+c,a+2c,...,b - (multiplier of a) < c');
+ equals(_.range(3, 10, 15).join(''), '3', 'range with three arguments a & b & c, c > 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');
+ });
+
});
View
@@ -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 generates an array of elements a,a+1,a+2,...,b-2,b-1');
- equals(_.range(8, 5).join(''), '', 'range with two arguments a & b, b<a generates an empty array');
- equals(_.range(3, 10, 3).join(' '), '3 6 9', 'range with three arguments a & b & c, c < b-a, a < b generates an array of elements a,a+c,a+2c,...,b - (multiplier of a) < c');
- equals(_.range(3, 10, 15).join(''), '3', 'range with three arguments a & b & c, c > 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');
- });
-});
-
View
@@ -63,4 +63,8 @@
return _.intersect(numbers, randomized);
});
+ JSLitmus.test('_.range()', function() {
+ return _.range(1000);
+ });
+
})();
View
@@ -7,7 +7,6 @@
<script type="text/javascript" src="vendor/qunit.js"></script>
<script type="text/javascript" src="vendor/jslitmus.js"></script>
<script type="text/javascript" src="../underscore.js"></script>
- <script type="text/javascript" src="generators.js"></script>
<script type="text/javascript" src="collections.js"></script>
<script type="text/javascript" src="arrays.js"></script>
<script type="text/javascript" src="functions.js"></script>
Oops, something went wrong.

0 comments on commit 4b2744a

Please sign in to comment.