react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / utility / range.js
80742 viewsvar isIterateeCall = require('../internal/isIterateeCall');12/** Native method references. */3var ceil = Math.ceil;45/* Native method references for those with the same name as other `lodash` methods. */6var nativeMax = Math.max;78/**9* Creates an array of numbers (positive and/or negative) progressing from10* `start` up to, but not including, `end`. If `end` is not specified it is11* set to `start` with `start` then set to `0`. If `end` is less than `start`12* a zero-length range is created unless a negative `step` is specified.13*14* @static15* @memberOf _16* @category Utility17* @param {number} [start=0] The start of the range.18* @param {number} end The end of the range.19* @param {number} [step=1] The value to increment or decrement by.20* @returns {Array} Returns the new array of numbers.21* @example22*23* _.range(4);24* // => [0, 1, 2, 3]25*26* _.range(1, 5);27* // => [1, 2, 3, 4]28*29* _.range(0, 20, 5);30* // => [0, 5, 10, 15]31*32* _.range(0, -4, -1);33* // => [0, -1, -2, -3]34*35* _.range(1, 4, 0);36* // => [1, 1, 1]37*38* _.range(0);39* // => []40*/41function range(start, end, step) {42if (step && isIterateeCall(start, end, step)) {43end = step = null;44}45start = +start || 0;46step = step == null ? 1 : (+step || 0);4748if (end == null) {49end = start;50start = 0;51} else {52end = +end || 0;53}54// Use `Array(length)` so engines like Chakra and V8 avoid slower modes.55// See https://youtu.be/XAqIpGU8ZZk#t=17m25s for more details.56var index = -1,57length = nativeMax(ceil((end - start) / (step || 1)), 0),58result = Array(length);5960while (++index < length) {61result[index] = start;62start += step;63}64return result;65}6667module.exports = range;686970