Sha256: 7e689f391f3c044251f47962524e5c5aa9c5571ee386c2a361d8f4fe8423639a

Contents?: true

Size: 1.33 KB

Versions: 264

Compression:

Stored size: 1.33 KB

Contents

var baseTimes = require('./_baseTimes'),
    castFunction = require('./_castFunction'),
    toInteger = require('./toInteger');

/** Used as references for various `Number` constants. */
var MAX_SAFE_INTEGER = 9007199254740991;

/** Used as references for the maximum length and index of an array. */
var MAX_ARRAY_LENGTH = 4294967295;

/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMin = Math.min;

/**
 * Invokes the iteratee `n` times, returning an array of the results of
 * each invocation. The iteratee is invoked with one argument; (index).
 *
 * @static
 * @since 0.1.0
 * @memberOf _
 * @category Util
 * @param {number} n The number of times to invoke `iteratee`.
 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
 * @returns {Array} Returns the array of results.
 * @example
 *
 * _.times(3, String);
 * // => ['0', '1', '2']
 *
 *  _.times(4, _.constant(0));
 * // => [0, 0, 0, 0]
 */
function times(n, iteratee) {
  n = toInteger(n);
  if (n < 1 || n > MAX_SAFE_INTEGER) {
    return [];
  }
  var index = MAX_ARRAY_LENGTH,
      length = nativeMin(n, MAX_ARRAY_LENGTH);

  iteratee = castFunction(iteratee);
  n -= MAX_ARRAY_LENGTH;

  var result = baseTimes(length, iteratee);
  while (++index < n) {
    iteratee(index);
  }
  return result;
}

module.exports = times;

Version data entries

264 entries across 262 versions & 29 rubygems

Version Path
sumomo-0.10.0 data/sumomo/api_modules/node_modules/lodash/times.js
reed_sdk-1.0.1 node_modules/lodash/times.js
reed_sdk-1.0.0 node_modules/lodash/times.js
boring_generators-0.12.0 tmp/templates/app_template/node_modules/lodash/times.js
sumomo-0.9.0 data/sumomo/api_modules/node_modules/lodash/times.js
sumomo-0.8.22 data/sumomo/api_modules/node_modules/lodash/times.js
sumomo-0.8.21 data/sumomo/api_modules/node_modules/lodash/times.js
sumomo-0.8.20 data/sumomo/api_modules/node_modules/lodash/times.js
sumomo-0.8.17 data/sumomo/api_modules/node_modules/lodash/times.js
sumomo-0.8.16 data/sumomo/api_modules/node_modules/lodash/times.js
disco_app-0.18.0 test/dummy/node_modules/lodash/times.js
disco_app-0.18.2 test/dummy/node_modules/lodash/times.js
sumomo-0.8.15 data/sumomo/api_modules/node_modules/lodash/times.js
trusty-cms-5.0.7 node_modules/lodash/times.js
appmap-0.72.2 ./node_modules/lodash/times.js
trusty-cms-5.0.6 node_modules/lodash/times.js
appmap-0.72.1 ./node_modules/lodash/times.js
appmap-0.72.0 ./node_modules/lodash/times.js
trusty-cms-5.0.5 node_modules/lodash/times.js
trusty-cms-5.0.4 node_modules/lodash/times.js