1 var baseTimes = require('./_baseTimes'),
2 castFunction = require('./_castFunction'),
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 `n` times, returning an array of the results of
16 * each invocation. The iteratee is invoked with one argument; (index).
22 * @param {number} n The number of times to invoke `iteratee`.
23 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
24 * @returns {Array} Returns the array of results.
28 * // => ['0', '1', '2']
30 * _.times(4, _.constant(0));
33 function times(n, iteratee) {
35 if (n < 1 || n > MAX_SAFE_INTEGER) {
38 var index = MAX_ARRAY_LENGTH,
39 length = nativeMin(n, MAX_ARRAY_LENGTH);
41 iteratee = castFunction(iteratee);
42 n -= MAX_ARRAY_LENGTH;
44 var result = baseTimes(length, iteratee);
51 module.exports = times;