Last active
May 9, 2018 00:01
-
-
Save hperrin/d8a60e3aeb6edd640f5c5c7ccb6b24ad to your computer and use it in GitHub Desktop.
JavaScript strRepeat. (Ridiculously efficient.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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