Q:

Write a JavaScript program to Iterate over a callback n times

0

Write a JavaScript program to Iterate over a callback n times.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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); // 01234

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now