Skip to content

Instantly share code, notes, and snippets.

@bingeboy
Created October 19, 2013 07:42
Show Gist options
  • Save bingeboy/7052744 to your computer and use it in GitHub Desktop.
Save bingeboy/7052744 to your computer and use it in GitHub Desktop.
String.prototype.repeat
String.prototype.repeat = function (count) {
var sDiff = "", sBase2 = count > 0 ? this.valueOf() : "";
for (var nMask = count; nMask > 1; nMask >>= 1) {
if (nMask & 1) { sDiff += sBase2; }
sBase2 += sBase2;
}
return sBase2 + sDiff;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment