“Función de repetición de JavaScript” Código de respuesta

Función de repetición personalizada de 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

Repita la cadena en JavaScript

let text = 'Hello world!';
let result = text.repeat(4);

console.log(result);
Mehedi Islam Ripon

Times de cadena JS

let string = 'Plumbus'
let count = 3

string.repeat(count); // -> 'PlumbusPlumbusPlumbus'
Evergreen Tomato

JavaScript Repet Character

var a="a";
var aaa=a.repeat(3); // "aaa"
Grepper

String Repet JavaScript

// best implementation
repeatStr = (n, s) => s.repeat(n);
Fylls

Función de repetición de 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

Respuestas similares a “Función de repetición de JavaScript”

Preguntas similares a “Función de repetición de JavaScript”

Más respuestas relacionadas con “Función de repetición de JavaScript” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código