Skip to content

Instantly share code, notes, and snippets.

@mrmurphy
Created December 12, 2013 06:13
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 mrmurphy/7923880 to your computer and use it in GitHub Desktop.
Save mrmurphy/7923880 to your computer and use it in GitHub Desktop.
var dict = ["a", "s", "d", "f"]
itoa = function (n) {
retstr = ""
while (n !== 0) {
digit = dict[(n % (dict.length + 1)) - 1]
retstr = digit + retstr
n = Math.floor(n / dict.length)
if (n === 1) {
n = 0
}
}
return retstr
}
console.log(itoa(1))
console.log(itoa(2))
console.log(itoa(3))
console.log(itoa(4))
console.log(itoa(5))
console.log(itoa(6))
console.log(itoa(7))
console.log(itoa(8))
console.log(itoa(9))
console.log(itoa(10))
@mrmurphy
Copy link
Author

This is supposed to print out:
a
s
d
f
aa
as
ad
af
etc..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment