source: imaps-frontend/node_modules/lodash-es/times.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 KB
Line 
1import baseTimes from './_baseTimes.js';
2import castFunction from './_castFunction.js';
3import toInteger from './toInteger.js';
4
5/** Used as references for various `Number` constants. */
6var MAX_SAFE_INTEGER = 9007199254740991;
7
8/** Used as references for the maximum length and index of an array. */
9var MAX_ARRAY_LENGTH = 4294967295;
10
11/* Built-in method references for those with the same name as other `lodash` methods. */
12var nativeMin = Math.min;
13
14/**
15 * Invokes the iteratee `n` times, returning an array of the results of
16 * each invocation. The iteratee is invoked with one argument; (index).
17 *
18 * @static
19 * @since 0.1.0
20 * @memberOf _
21 * @category Util
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.
25 * @example
26 *
27 * _.times(3, String);
28 * // => ['0', '1', '2']
29 *
30 * _.times(4, _.constant(0));
31 * // => [0, 0, 0, 0]
32 */
33function times(n, iteratee) {
34 n = toInteger(n);
35 if (n < 1 || n > MAX_SAFE_INTEGER) {
36 return [];
37 }
38 var index = MAX_ARRAY_LENGTH,
39 length = nativeMin(n, MAX_ARRAY_LENGTH);
40
41 iteratee = castFunction(iteratee);
42 n -= MAX_ARRAY_LENGTH;
43
44 var result = baseTimes(length, iteratee);
45 while (++index < n) {
46 iteratee(index);
47 }
48 return result;
49}
50
51export default times;
Note: See TracBrowser for help on using the repository browser.