Skip to content

Instantly share code, notes, and snippets.

@leodutra
Created December 28, 2015 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leodutra/c54de755d9d64c914616 to your computer and use it in GitHub Desktop.
Save leodutra/c54de755d9d64c914616 to your computer and use it in GitHub Desktop.
String repeat polyfill for JavaScript
function repeat(str, times) {
var n = times | 0;
var res = '';
var buffer = str;
for (;;) {
if (n & 1) res += buffer;
if (n >>= 1) buffer += buffer;
else break;
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment