Skip to content

Instantly share code, notes, and snippets.

@bruslim
Last active August 29, 2015 14:04
Show Gist options
  • Save bruslim/1e4d00e55ce32b8f3e3b to your computer and use it in GitHub Desktop.
Save bruslim/1e4d00e55ce32b8f3e3b to your computer and use it in GitHub Desktop.
String.prototype.repeat Shim
// Repeat Shim
String.prototype.repeat = String.prototype.repeat || function(count) {
// temporary return array
var ret = [];
// count to count
for(var i = 0; i < count; i++) {
// push this (the string we want to repeat)
// into the array
ret.push(this);
}
// use Array.prototype.join to concat
// all the string together.
return ret.join('');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment