Created
September 10, 2012 22:02
-
-
Save wafflesnatcha/3694273 to your computer and use it in GitHub Desktop.
JavaScript: String.repeat()
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
/** | |
* Return the string repeated {multiplier} times. | |
* | |
* @param {Number} multiplier Number of times to repeat the string. | |
* @returns {String} The repeated string. | |
*/ | |
if (!String.prototype.repeat) { | |
String.prototype.repeat = function (multiplier) { | |
return new Array(multiplier + 1).join(this); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment