Skip to content

Instantly share code, notes, and snippets.

@wafflesnatcha
Created September 10, 2012 22:02
Show Gist options
  • Save wafflesnatcha/3694273 to your computer and use it in GitHub Desktop.
Save wafflesnatcha/3694273 to your computer and use it in GitHub Desktop.
JavaScript: String.repeat()
/**
* 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