Skip to content

Instantly share code, notes, and snippets.

@rodpoblete
Last active May 26, 2017 19:36
Show Gist options
  • Save rodpoblete/a4aab26933de683a5c5a025ff98e9898 to your computer and use it in GitHub Desktop.
Save rodpoblete/a4aab26933de683a5c5a025ff98e9898 to your computer and use it in GitHub Desktop.
Función repetir string x numero de veces - FCC [249]
function repeatStringNumTimes(str, num) {
if (num > 0) { // valida si el numero de repeticiones es un numero positivo
var repeatString = str.repeat(num); // funcion repeat con el parametro numero ingresado a la funcion
return console.log(repeatString); // retorma el string repetido
} else {
return console.log(""); // devuelve vacio si es un numero negativo,
}
}
repeatStringNumTimes("hola",2); // "holahola"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment