Skip to content

Instantly share code, notes, and snippets.

@mijimoco
Created January 17, 2017 12:34
Show Gist options
  • Save mijimoco/4a7027a926c28205f9f48ea2e4b53060 to your computer and use it in GitHub Desktop.
Save mijimoco/4a7027a926c28205f9f48ea2e4b53060 to your computer and use it in GitHub Desktop.
Repeat a string repeat a string
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