n timesFunction.prototype.call() to call fn n times or until it returns false.context, to use an undefined object (or the global object in non-strict mode).const times = (n, fn, context = undefined) => {
let i = 0;
while (fn.call(context, i) !== false && ++i < n) {}
};
var output = '';
times(5, i => (output += i));
console.log(output); // 01234Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️