Skip to content

Instantly share code, notes, and snippets.

@nmenglund
Created September 17, 2013 08:24
Show Gist options
  • Select an option

  • Save nmenglund/6591516 to your computer and use it in GitHub Desktop.

Select an option

Save nmenglund/6591516 to your computer and use it in GitHub Desktop.
JS: Repeat a given string 'num' times
// Repeat a given string 'num' times
String.prototype.repeat = function(num)
{
if (num == 1)
return this.toString();
else if (num < 1)
return "";
else
return new Array(+num + 1).join(this.toString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment