Skip to content

Instantly share code, notes, and snippets.

@hperrin
Last active May 9, 2018 00:01
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 hperrin/d8a60e3aeb6edd640f5c5c7ccb6b24ad to your computer and use it in GitHub Desktop.
Save hperrin/d8a60e3aeb6edd640f5c5c7ccb6b24ad to your computer and use it in GitHub Desktop.
JavaScript strRepeat. (Ridiculously efficient.)
export default function strRepeat (str, repeat) {
let curStr = str, i = 1, result = '';
while (true) {
if (i & repeat) result += curStr;
i *= 2;
if (i >= repeat) break;
curStr += curStr;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment