underscore-source 0.4.5 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,7 +31,7 @@
|
|
31
31
|
if (typeof exports !== 'undefined') exports._ = _;
|
32
32
|
|
33
33
|
// Current version.
|
34
|
-
_.VERSION = '0.4.
|
34
|
+
_.VERSION = '0.4.6';
|
35
35
|
|
36
36
|
/*------------------------ Collection Functions: ---------------------------*/
|
37
37
|
|
@@ -216,7 +216,8 @@
|
|
216
216
|
|
217
217
|
// Convert anything iterable into a real, live array.
|
218
218
|
_.toArray = function(iterable) {
|
219
|
-
if (!iterable)
|
219
|
+
if (!iterable) return [];
|
220
|
+
if (iterable.toArray) return iterable.toArray();
|
220
221
|
if (_.isArray(iterable)) return iterable;
|
221
222
|
return _.map(iterable, function(val){ return val; });
|
222
223
|
};
|
@@ -314,6 +315,22 @@
|
|
314
315
|
return -1;
|
315
316
|
};
|
316
317
|
|
318
|
+
// Generate an integer Array containing an arithmetic progression. A port of
|
319
|
+
// the native Python range() function. See:
|
320
|
+
// http://docs.python.org/library/functions.html#range
|
321
|
+
_.range = function(start, stop, step) {
|
322
|
+
var a = _.toArray(arguments);
|
323
|
+
var solo = a.length <= 1;
|
324
|
+
var start = solo ? 0 : a[0], stop = solo ? a[0] : a[1], step = a[2] || 1;
|
325
|
+
var len = Math.ceil((stop - start) / step);
|
326
|
+
if (len <= 0) return [];
|
327
|
+
var range = new Array(len);
|
328
|
+
for (var i = start, idx = 0; true; i += step) {
|
329
|
+
if ((step > 0 ? i - stop : stop - i) >= 0) return range;
|
330
|
+
range[idx++] = i;
|
331
|
+
}
|
332
|
+
};
|
333
|
+
|
317
334
|
/* ----------------------- Function Functions: -----------------------------*/
|
318
335
|
|
319
336
|
// Create a function bound to a given object (assigning 'this', and arguments,
|