Skip to content

Instantly share code, notes, and snippets.

@AndriiBozh
Created January 14, 2018 13:33
Show Gist options
  • Save AndriiBozh/a4ebbf94963047258885a3416703572b to your computer and use it in GitHub Desktop.
Save AndriiBozh/a4ebbf94963047258885a3416703572b to your computer and use it in GitHub Desktop.
Repeat a String (freeCodeCamp challenge)
/* assignment: Repeat a given string (first argument) num times (second argument).
Return an empty string if num is not a positive number.
*/
function repeatStringNumTimes(str, num) {
if (num <= 0) {
return ""; // return empty string
}
return str.repeat(num); // The repeat() method constructs and returns a new string which contains the specified number (num) of copies
} // of the string on which it was called, concatenated together.
repeatStringNumTimes("abc", 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment