1 var isIterateeCall = require('../internal/isIterateeCall');
3 /* Native method references for those with the same name as other `lodash` methods. */
4 var nativeCeil = Math.ceil,
8 * Creates an array of numbers (positive and/or negative) progressing from
9 * `start` up to, but not including, `end`. If `end` is not specified it's
10 * set to `start` with `start` then set to `0`. If `end` is less than `start`
11 * a zero-length range is created unless a negative `step` is specified.
16 * @param {number} [start=0] The start of the range.
17 * @param {number} end The end of the range.
18 * @param {number} [step=1] The value to increment or decrement by.
19 * @returns {Array} Returns the new array of numbers.
29 * // => [0, 5, 10, 15]
32 * // => [0, -1, -2, -3]
40 function range(start, end, step) {
41 if (step && isIterateeCall(start, end, step)) {
42 end = step = undefined;
45 step = step == null ? 1 : (+step || 0);
53 // Use `Array(length)` so engines like Chakra and V8 avoid slower modes.
54 // See https://youtu.be/XAqIpGU8ZZk#t=17m25s for more details.
56 length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
57 result = Array(length);
59 while (++index < length) {
60 result[index] = start;
66 module.exports = range;