Last active
May 26, 2017 19:36
-
-
Save rodpoblete/a4aab26933de683a5c5a025ff98e9898 to your computer and use it in GitHub Desktop.
Función repetir string x numero de veces - FCC [249]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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