Skip to content

Instantly share code, notes, and snippets.

@aaronbeall
Created February 9, 2019 02:37
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 aaronbeall/cb249c26ca38eac5c08de7ca681d83e7 to your computer and use it in GitHub Desktop.
Save aaronbeall/cb249c26ca38eac5c08de7ca681d83e7 to your computer and use it in GitHub Desktop.
function numberToText(num: number, numStrings: string[]): string {
let str = "";
do {
const r = num % numStrings.length;
num = Math.floor(num / numStrings.length);
str = `${numStrings[r]}${str}`;
} while (num > 0);
return str;
}
alert(numberToText(45, ["0", "1"])) // "101101"
alert(numberToText(79, "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("")) // "DB"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment