Skip to content

Instantly share code, notes, and snippets.

@DStereo
Last active May 4, 2016 09:00
Show Gist options
  • Save DStereo/adb5b7d8a77f3b47ee1010b0d1d879bc to your computer and use it in GitHub Desktop.
Save DStereo/adb5b7d8a77f3b47ee1010b0d1d879bc to your computer and use it in GitHub Desktop.
Repeat string in prototypal manner
if (String.prototype.repeat !== 'function') {
String.prototype.repeat = function(times) {
if (typeof times !== 'number') {
return this;
}
return Array(times + 1).join(this);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment