Security update for permissions_by_term
[yaffs-website] / node_modules / uncss / node_modules / lodash / times.js
1 var baseTimes = require('./internal/baseTimes'),
2     toFunction = require('./internal/toFunction'),
3     toInteger = require('./toInteger');
4
5 /** Used as references for various `Number` constants. */
6 var MAX_SAFE_INTEGER = 9007199254740991;
7
8 /** Used as references for the maximum length and index of an array. */
9 var MAX_ARRAY_LENGTH = 4294967295;
10
11 /* Built-in method references for those with the same name as other `lodash` methods. */
12 var nativeMin = Math.min;
13
14 /**
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).
17  *
18  * @static
19  * @memberOf _
20  * @category Util
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.
24  * @example
25  *
26  * _.times(3, String);
27  * // => ['0', '1', '2']
28  *
29  *  _.times(4, _.constant(true));
30  * // => [true, true, true, true]
31  */
32 function times(n, iteratee) {
33   n = toInteger(n);
34   if (n < 1 || n > MAX_SAFE_INTEGER) {
35     return [];
36   }
37   var index = MAX_ARRAY_LENGTH,
38       length = nativeMin(n, MAX_ARRAY_LENGTH);
39
40   iteratee = toFunction(iteratee);
41   n -= MAX_ARRAY_LENGTH;
42
43   var result = baseTimes(length, iteratee);
44   while (++index < n) {
45     iteratee(index);
46   }
47   return result;
48 }
49
50 module.exports = times;