Created
January 17, 2017 12:34
-
-
Save mijimoco/4a7027a926c28205f9f48ea2e4b53060 to your computer and use it in GitHub Desktop.
Repeat a string repeat a string
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) { | |
// repeat after me | |
if (num > 0) { | |
var newString = ""; | |
for (i=0; i<num; ++i) { | |
newString += str; | |
} | |
console.log(newString); | |
return newString; | |
} else return ""; | |
} | |
repeatStringNumTimes("abc", -1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment