Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
split, reduce solution in Clear category for [old] Worth of Words by Sim0000
"use strict";
function worthOfWords(words) {
let D = {
'e':1,'a':1,'i':1,'o':1,'n':1,'r':1,'t':1,'l':1,'s':1,'u':1,'d':2,'g':2,
'b':3,'c':3,'m':3,'p':3,'f':4,'h':4,'v':4,'w':4,'y':4,'k':5,'j':8,'x':8,
'q':10,'z':10
};
let maxw, maxp = 0;
for(let word of words){
let point = word.split("").reduce((a, c) => a + D[c], 0);
if(point > maxp){
maxp = point;
maxw = word;
}
}
return maxw;
}
var assert = require('assert');
if (!global.is_checking) {
// These "asserts" are used for self-checking and not for an auto-testing
assert.equal(worthOfWords(['hi', 'quiz', 'bomb', 'president']), 'quiz')
assert.equal(worthOfWords(['zero', 'one', 'two', 'three', 'four', 'five']), 'zero')
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
March 16, 2018