Created
January 26, 2013 04:32
-
-
Save oyvindkinsey/4640228 to your computer and use it in GitHub Desktop.
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
var input = 'ABbCcc\n\ | |
Good luck in the Facebook Hacker Cup this year!\n\ | |
Ignore punctuation, please :\n)\ | |
Sometimes test cases are hard to make up\n.\ | |
So I just go consult Professor Dalves'; | |
input.split('\n').forEach(function(line) { | |
console.log( | |
line, | |
line | |
.toLowerCase() | |
.replace(/[^a-z]/g, '') | |
.split('') | |
.reduce(function(p, c) { | |
p[c.charCodeAt(0)] = (p[c.charCodeAt(0)] || 0) + 1; | |
return p; | |
}, []) | |
.filter(function(v) { | |
return v; | |
}) | |
.sort() | |
.reverse() | |
.reduce(function(p, c, i) { | |
return p + (26 - i) * c; | |
}, 0) | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment