mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09:27:49 +00:00
Bump to v3.0.0.
This commit is contained in:
76
lodash.range/index.js
Normal file
76
lodash.range/index.js
Normal file
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* lodash 3.0.0 (Custom Build) <https://lodash.com/>
|
||||
* Build: `lodash modern modularize exports="npm" -o ./`
|
||||
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
||||
* Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>
|
||||
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
||||
* Available under MIT license <https://lodash.com/license>
|
||||
*/
|
||||
var isIterateeCall = require('lodash._isiterateecall');
|
||||
|
||||
/** Native method references. */
|
||||
var ceil = Math.ceil;
|
||||
|
||||
/* Native method references for those with the same name as other `lodash` methods. */
|
||||
var nativeMax = Math.max;
|
||||
|
||||
/**
|
||||
* Creates an array of numbers (positive and/or negative) progressing from
|
||||
* `start` up to, but not including, `end`. If `end` is not specified it is
|
||||
* set to `start` with `start` then set to `0`. If `end` is less than `start`
|
||||
* a zero-length range is created unless a negative `step` is specified.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Utility
|
||||
* @param {number} [start=0] The start of the range.
|
||||
* @param {number} end The end of the range.
|
||||
* @param {number} [step=1] The value to increment or decrement by.
|
||||
* @returns {Array} Returns the new array of numbers.
|
||||
* @example
|
||||
*
|
||||
* _.range(4);
|
||||
* // => [0, 1, 2, 3]
|
||||
*
|
||||
* _.range(1, 5);
|
||||
* // => [1, 2, 3, 4]
|
||||
*
|
||||
* _.range(0, 20, 5);
|
||||
* // => [0, 5, 10, 15]
|
||||
*
|
||||
* _.range(0, -4, -1);
|
||||
* // => [0, -1, -2, -3]
|
||||
*
|
||||
* _.range(1, 4, 0);
|
||||
* // => [1, 1, 1]
|
||||
*
|
||||
* _.range(0);
|
||||
* // => []
|
||||
*/
|
||||
function range(start, end, step) {
|
||||
if (step && isIterateeCall(start, end, step)) {
|
||||
end = step = null;
|
||||
}
|
||||
start = +start || 0;
|
||||
step = step == null ? 1 : (+step || 0);
|
||||
|
||||
if (end == null) {
|
||||
end = start;
|
||||
start = 0;
|
||||
} else {
|
||||
end = +end || 0;
|
||||
}
|
||||
// Use `Array(length)` so engines like Chakra and V8 avoid slower modes.
|
||||
// See https://youtu.be/XAqIpGU8ZZk#t=17m25s for more details.
|
||||
var index = -1,
|
||||
length = nativeMax(ceil((end - start) / (step || 1)), 0),
|
||||
result = Array(length);
|
||||
|
||||
while (++index < length) {
|
||||
result[index] = start;
|
||||
start += step;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = range;
|
||||
Reference in New Issue
Block a user