Last active
January 23, 2018 22:42
-
-
Save mattdiamond/8ca5fd30ee5a9719c8bdf507186e8c14 to your computer and use it in GitHub Desktop.
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
function convertToBase(number, base){ | |
let value = number, | |
remainder, | |
result = ''; | |
while (value !== 0) { | |
remainder = value % base; | |
value = ~~(value / base); | |
if (remainder < 0){ | |
value += 1; | |
remainder -= base; | |
} | |
result = remainder + result; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment