Skip to content

Instantly share code, notes, and snippets.

@mmloveaa
Last active April 5, 2016 01:07
Show Gist options
  • Save mmloveaa/6b05b865ba85140850f561ced805fefa to your computer and use it in GitHub Desktop.
Save mmloveaa/6b05b865ba85140850f561ced805fefa to your computer and use it in GitHub Desktop.
4-4 FCC Q8 - Repeat a string
Repeat a string repeat a string
Repeat a given string (first argument) num times (second argument). Return an empty string if num is a negative number.
Remember to use Read-Search-Ask if you get stuck. Write your own code.
Here are some helpful links:
Global String Object
function repeatStringNumTimes(str, num) {
// repeat after me
if(num<0){
return "";
} else {
return str.repeat(num);
}
}
repeatStringNumTimes("abc", 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment