Skip to content

Instantly share code, notes, and snippets.

@omas
Created January 5, 2015 06:08
Show Gist options
  • Save omas/17b901bbd744bdc9d49b to your computer and use it in GitHub Desktop.
Save omas/17b901bbd744bdc9d49b to your computer and use it in GitHub Desktop.
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk) {
var lines = chunk.split('\n');
var len = parseInt(lines.shift(),10);
var result = (function(grades) {
var score_table = {
'A':4,'B':3,'C':2,'D':1,'F':0
};
var sum = grades.map(function(v) {
return score_table[v];
})
.reduce(function(prev,current) {
return prev + current;
});
return sum / grades.length;
}(lines[0].toString().split('').slice(0,len)));
console.log(result);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment