test-action-debian-package/node_modules/ramda/es/times.js
Dawid Dziurla 9308795b8b
update
2020-03-26 15:37:35 +01:00

47 lines
1.1 KiB
JavaScript

import _curry2 from "./internal/_curry2.js";
/**
* Calls an input function `n` times, returning an array containing the results
* of those function calls.
*
* `fn` is passed one argument: The current value of `n`, which begins at `0`
* and is gradually incremented to `n - 1`.
*
* @func
* @memberOf R
* @since v0.2.3
* @category List
* @sig (Number -> a) -> Number -> [a]
* @param {Function} fn The function to invoke. Passed one argument, the current value of `n`.
* @param {Number} n A value between `0` and `n - 1`. Increments after each function call.
* @return {Array} An array containing the return values of all calls to `fn`.
* @see R.repeat
* @example
*
* R.times(R.identity, 5); //=> [0, 1, 2, 3, 4]
* @symb R.times(f, 0) = []
* @symb R.times(f, 1) = [f(0)]
* @symb R.times(f, 2) = [f(0), f(1)]
*/
var times =
/*#__PURE__*/
_curry2(function times(fn, n) {
var len = Number(n);
var idx = 0;
var list;
if (len < 0 || isNaN(len)) {
throw new RangeError('n must be a non-negative number');
}
list = new Array(len);
while (idx < len) {
list[idx] = fn(idx);
idx += 1;
}
return list;
});
export default times;