1 var baseTimes = require('./_baseTimes'),
2 toFunction = require('./_toFunction'),
3 toInteger = require('./toInteger');
5 /** Used as references for various `Number` constants. */
6 var MAX_SAFE_INTEGER = 9007199254740991;
8 /** Used as references for the maximum length and index of an array. */
9 var MAX_ARRAY_LENGTH = 4294967295;
11 /* Built-in method references for those with the same name as other `lodash` methods. */
12 var nativeMin = Math.min;
15 * Invokes the iteratee function `n` times, returning an array of the results
16 * of each invocation. The iteratee is invoked with one argument; (index).
21 * @param {number} n The number of times to invoke `iteratee`.
22 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
23 * @returns {Array} Returns the array of results.
27 * // => ['0', '1', '2']
29 * _.times(4, _.constant(true));
30 * // => [true, true, true, true]
32 function times(n, iteratee) {
34 if (n < 1 || n > MAX_SAFE_INTEGER) {
37 var index = MAX_ARRAY_LENGTH,
38 length = nativeMin(n, MAX_ARRAY_LENGTH);
40 iteratee = toFunction(iteratee);
41 n -= MAX_ARRAY_LENGTH;
43 var result = baseTimes(length, iteratee);
50 module.exports = times;