function-repeat
v0.0.1
Published
function `repeat` construct an array by repeating a value (or function) a number of times, synchronously.
Downloads
3
Readme
function-repeat
function repeat
construct an array by repeating a value (or function) a number of times, synchronously.
INSTALL:
npm install function-repeat
USAGE:
repeat(val, n)
var repeat = require('function-repeat');
var res = repeat(1, 4); // -> [1, 1, 1, 1]
var res = repeat('a', 4); // -> ['a', 'a', 'a', 'a']
repeat(fn, n, context, arguments,...)
var repeat = require('function-repeat');
function fn1() {
return 2;
}
var res = repeat(fn1, 5); // -> [2, 2, 2, 2, 2]
function fn2(x, y) {
return x + y;
}
var res = repeat(fn2, 5, null, 2, 3); // -> [5, 5, 5, 5, 5]
function fn3(x) {
return this + x;
}
var res = repeat(fn3, 5, 2, 3); // -> [5, 5, 5, 5, 5]
Function.prototype.repeat(n, context, arguments,...)
var repeat = require('function-repeat').extendFunctionRepeat();
function fn1() {
return 2;
}
var res = fn1.repeat(5); // -> [2, 2, 2, 2, 2]
function fn2(x, y) {
return x + y;
}
var res = fn2.repeat(5, null, 2, 3); // -> [5, 5, 5, 5, 5]
function fn3(x) {
return this + x;
}
var res = fn3.repeat(5, 2, 3); // -> [5, 5, 5, 5, 5]
SEE ALSO:
call-n-times, times, repeat-function
LICENSE:
MIT