1 var isIterateeCall = require('../internal/isIterateeCall');
3 /** Native method references. */
6 /* Native method references for those with the same name as other `lodash` methods. */
7 var nativeMax = Math.max;
10 * Creates an array of numbers (positive and/or negative) progressing from
11 * `start` up to, but not including, `end`. If `end` is not specified it is
12 * set to `start` with `start` then set to `0`. If `end` is less than `start`
13 * a zero-length range is created unless a negative `step` is specified.
18 * @param {number} [start=0] The start of the range.
19 * @param {number} end The end of the range.
20 * @param {number} [step=1] The value to increment or decrement by.
21 * @returns {Array} Returns the new array of numbers.
31 * // => [0, 5, 10, 15]
34 * // => [0, -1, -2, -3]
42 function range(start, end, step) {
43 if (step && isIterateeCall(start, end, step)) {
47 step = step == null ? 1 : (+step || 0);
55 // Use `Array(length)` so engines like Chakra and V8 avoid slower modes.
56 // See https://youtu.be/XAqIpGU8ZZk#t=17m25s for more details.
58 length = nativeMax(ceil((end - start) / (step || 1)), 0),
59 result = Array(length);
61 while (++index < length) {
62 result[index] = start;
68 module.exports = range;