mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 11:57:49 +00:00
"Cleaned up"? _.range (or maybe not)
This commit is contained in:
@@ -353,16 +353,19 @@
|
|||||||
// the native Python `range()` function. See
|
// the native Python `range()` function. See
|
||||||
// [the Python documentation](http://docs.python.org/library/functions.html#range).
|
// [the Python documentation](http://docs.python.org/library/functions.html#range).
|
||||||
_.range = function(start, stop, step) {
|
_.range = function(start, stop, step) {
|
||||||
var a = slice.call(arguments);
|
var args = slice.call(arguments),
|
||||||
var solo = a.length <= 1;
|
solo = args.length <= 1,
|
||||||
var start = solo ? 0 : a[0], stop = solo ? a[0] : a[1], step = a[2] || 1;
|
start = solo ? 0 : args[0],
|
||||||
var len = Math.ceil((stop - start) / step);
|
stop = solo ? args[0] : args[1],
|
||||||
if (len <= 0) return [];
|
step = args[2] || 1,
|
||||||
var range = new Array(len);
|
len = Math.max(Math.ceil((stop - start) / step), 0),
|
||||||
for (var i = start, idx = 0; true; i += step) {
|
idx = 0,
|
||||||
if ((step > 0 ? i - stop : stop - i) >= 0) return range;
|
range = new Array(len);
|
||||||
range[idx++] = i;
|
while (idx < len) {
|
||||||
|
range[idx++] = start;
|
||||||
|
start += step;
|
||||||
}
|
}
|
||||||
|
return range;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function Functions
|
// Function Functions
|
||||||
|
|||||||
Reference in New Issue
Block a user