Skip to content

Instantly share code, notes, and snippets.

@mattdiamond
Last active January 23, 2018 22:42
Show Gist options
  • Save mattdiamond/8ca5fd30ee5a9719c8bdf507186e8c14 to your computer and use it in GitHub Desktop.
Save mattdiamond/8ca5fd30ee5a9719c8bdf507186e8c14 to your computer and use it in GitHub Desktop.
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