Created
January 3, 2022 07:40
-
-
Save Sanchithasharma/b4b96a4bafc3fdd90a74b8ff64147907 to your computer and use it in GitHub Desktop.
Repeat a String Repeat a String
This file contains 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 || 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