Skip to content

Instantly share code, notes, and snippets.

@HyShai
Last active August 29, 2015 14:15
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 HyShai/1f63fc8d54fb5bba5056 to your computer and use it in GitHub Desktop.
Save HyShai/1f63fc8d54fb5bba5056 to your computer and use it in GitHub Desktop.
Solve the Trello dev challenge (https://trello.com/jobs/developer) recursively using ES6 features.
function unhash(hash, str="") { //default parameter values currently only supported by Firefox
var base = 7;
var multiplier = 37;
var letters = "acdegilmnoprstuw";
var index = hash % multiplier;
str = letters[index] + str;
hash = Math.trunc(hash / multiplier);
//Math.trunc is a dumb Math.floor - splits by the decimal point
//so works for negative numbers also
//(obviously doesn't make a difference here,
//but it's recommended over Math.floor to get the quotient)
if (hash === base)
return str
return unhash(hash, str)
}
unhash(956446786872726) === "trellises"
//this is how babel transpiled the code to ES5 - wow
function unhash(_x2) {
var _arguments = arguments;
_function: while (true) {
var hash = _x2;
str = base = multiplier = letters = index = undefined;
var str = _arguments[1] === undefined ? "" : _arguments[1];
//default parameter values currently only supported by Firefox
var base = 7;
var multiplier = 37;
var letters = "acdegilmnoprstuw";
var index = hash % multiplier;
str = letters[index] + str;
hash = Math.trunc(hash / multiplier);
//Math.trunc is a dumb Math.floor - splits by the decimal point
//so works for negative numbers also
//(obviously doesn't make a difference here,
//but it's recommended over Math.floor to get the quotient)
if (hash === base) {
return str;
}_arguments = [_x2 = hash, str];
continue _function;
}
}
unhash(956446786872726) === "trellises";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment