“fungsi pengulangan kustom javascript” Kode Jawaban

fungsi pengulangan kustom javascript

/* 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
Intra

Ulangi fungsi javascript

setInterval(function(){
  console.log("Hello");
  console.log("World");
}, 2000); //repeat every 2s
TalalDEV

Fungsi Ulangi JavaScript

/* The string.repeat(n) method constructs and returns a new string
with "n" number of copies. */

const chorus = "Because I'm happy. ";
console.log(`Chorus lyrics: ${chorus.repeat(3)}`);
// → "Chorus lyrics: Because I'm happy. Because I'm happy. Because I'm happy. "

// Use within a function
greeting = (n, words) => words.repeat(n);
console.log(greeting(5, "howdy ")); 
// → "howdy howdy howdy howdy howdy "
Intra

Jawaban yang mirip dengan “fungsi pengulangan kustom javascript”

Pertanyaan yang mirip dengan “fungsi pengulangan kustom javascript”

Lebih banyak jawaban terkait untuk “fungsi pengulangan kustom javascript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya