Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript custom repeat function

/* Build a custom repeat function: perform an action "n" times. */

repeat = (n, action) => {
  for (let i = 0; i < n; i++) {
    action(i);
  }
}

repeat(5, n => {
  console.log(2 * n);
});
// → 0 2 4 6 8
Source by eloquentjavascript.net #
 
PREVIOUS NEXT
Tagged: #javascript #custom #repeat #function
ADD COMMENT
Topic
Name
9+3 =