times source npm
_.times(n, [iteratee=_.identity])
Invokes the iteratee function n
times, returning an array of the results
of each invocation. The iteratee is invoked with one argument; (index).
Arguments
- n (number)
The number of times to invoke
iteratee
. - [iteratee=_.identity] (Function)
The function invoked per iteration.
Returns (Array)
Returns the array of results.
Example
var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
// => [3, 6, 4]
_.times(3, function(n) {
mage.castSpell(n);
});
// => invokes `mage.castSpell` three times with `n` of `0`, `1`, and `2`