Skip to content

Instantly share code, notes, and snippets.

@Sanchithasharma
Created January 3, 2022 07:40
Show Gist options
  • Save Sanchithasharma/b4b96a4bafc3fdd90a74b8ff64147907 to your computer and use it in GitHub Desktop.
Save Sanchithasharma/b4b96a4bafc3fdd90a74b8ff64147907 to your computer and use it in GitHub Desktop.
Repeat a String Repeat a String
function repeatStringNumTimes(str, num) {
if (num === 0 || Math.sign(num) === -1) {
return ""
}
let arr = [str]
let i = 1
while (i< num) {
arr.push(str)
i++
}
return arr.join('');
}
repeatStringNumTimes("abc", 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment