| /** |
| * Lo-Dash 2.4.1 (Custom Build) <http://lodash.com/> |
| * Build: `lodash modularize exports="node" -o ./compat/` |
| * Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/> |
| * Based on Underscore.js 1.5.2 <http://underscorejs.org/LICENSE> |
| * Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors |
| * Available under MIT license <http://lodash.com/license> |
| */ |
| |
| /** Native method shortcuts */ |
| var ceil = Math.ceil; |
| |
| /* Native method shortcuts for methods 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 `start` is less than `stop` a |
| * zero-length range is created unless a negative `step` is specified. |
| * |
| * @static |
| * @memberOf _ |
| * @category Arrays |
| * @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 a new range array. |
| * @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) { |
| start = +start || 0; |
| step = typeof step == 'number' ? step : (+step || 1); |
| |
| if (end == null) { |
| end = start; |
| start = 0; |
| } |
| // use `Array(length)` so engines like Chakra and V8 avoid slower modes |
| // http://youtu.be/XAqIpGU8ZZk#t=17m25s |
| var index = -1, |
| length = nativeMax(0, ceil((end - start) / (step || 1))), |
| result = Array(length); |
| |
| while (++index < length) { |
| result[index] = start; |
| start += step; |
| } |
| return result; |
| } |
| |
| module.exports = range; |