Created
August 15, 2015 22:52
-
-
Save avdg/a11df1fff3d8b4641757 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function duplicate(value, count) { | |
var output = []; | |
var duplicator = [value]; | |
var base = 1; | |
while (count > 0) { | |
if ((base & count) > 0) { | |
output = output.concat(duplicator); | |
count -= base; | |
} | |
duplicator = duplicator.concat(duplicator); | |
base = base << 1; // this was just "base << 1" and didn't store the result, resulting in an infinite loop | |
} | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment