Times first count
items from array
Number count
Any Number
Function cb
Any Function
to call count
times.
thisArg
optionalWill be the value of this
within cb
.
import { Times } from "@taystack/js-helpers";
let val = 1;
Times(4, (i) => val += i);
// val + i
// 1 + 0 = 1
// 1 + 1 = 2
// 2 + 2 = 4
// 4 + 3 = 7
In a bit of action:
class Fighter {
constructor() {
this.attacks = 3;
}
get attack() {
return Random(1, 4);
}
attackTarget(target) {
Times(this.attacks, () => {
target.takeDamage(this.attack);
});
}
}
Source: @taystack/js-helpers hosted on GitHub Author: taystack