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
# Goals | |
# | |
# 1. Mix promise and non-promise arguments | |
# 2. Behaves like a normal function if all arguments are non-promise | |
# 3. Returns a promise if any non-promise argument | |
# 4. Use no promise library, rely on the fact that: | |
# promise.then(-> a1).then((a2) -> a1 === a2) | |
# promise.then(-> Promise(a1)).then((a2) -> a1 === a2) | |
# |
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
alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split("") | |
base = alphabet.length | |
exports.encode = (i) -> | |
return alphabet[0] if i is 0 | |
s = "" | |
while i > 0 | |
s += alphabet[i % base] | |
i = parseInt(i / base, 10) |