react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / utility / times.js
80742 viewsvar bindCallback = require('../internal/bindCallback');12/** Native method references. */3var floor = Math.floor;45/* Native method references for those with the same name as other `lodash` methods. */6var nativeIsFinite = global.isFinite,7nativeMin = Math.min;89/** Used as references for the maximum length and index of an array. */10var MAX_ARRAY_LENGTH = 4294967295;1112/**13* Invokes the iteratee function `n` times, returning an array of the results14* of each invocation. The `iteratee` is bound to `thisArg` and invoked with15* one argument; (index).16*17* @static18* @memberOf _19* @category Utility20* @param {number} n The number of times to invoke `iteratee`.21* @param {Function} [iteratee=_.identity] The function invoked per iteration.22* @param {*} [thisArg] The `this` binding of `iteratee`.23* @returns {Array} Returns the array of results.24* @example25*26* var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));27* // => [3, 6, 4]28*29* _.times(3, function(n) {30* mage.castSpell(n);31* });32* // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2`33*34* _.times(3, function(n) {35* this.cast(n);36* }, mage);37* // => also invokes `mage.castSpell(n)` three times38*/39function times(n, iteratee, thisArg) {40n = floor(n);4142// Exit early to avoid a JSC JIT bug in Safari 843// where `Array(0)` is treated as `Array(1)`.44if (n < 1 || !nativeIsFinite(n)) {45return [];46}47var index = -1,48result = Array(nativeMin(n, MAX_ARRAY_LENGTH));4950iteratee = bindCallback(iteratee, thisArg, 1);51while (++index < n) {52if (index < MAX_ARRAY_LENGTH) {53result[index] = iteratee(index);54} else {55iteratee(index);56}57}58return result;59}6061module.exports = times;626364