mirror of
https://github.com/swc-project/swc.git
synced 2024-12-30 00:52:29 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
// Loaded from https://deno.land/x/ramda@v0.27.2/source/times.js
|
|
|
|
|
|
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 = _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;
|