scoreWordGame_v2 = (list, scores) => {
let arrayWithScore = list
.map((d) => ({
score: getWordScore(d, scores),
word: d
}))
.sort((a, b) => {
if (b.score === a.score) {
return a.word.localeCompare(b.word);
}
return b.score - a.score;
});
let maxScore = arrayWithScore[0].score;
let highestScoringWords = arrayWithScore.filter(
(item) => item.score === maxScore
);
if (highestScoringWords.length === 1) {
return highestScoringWords[0].word;
}
highestScoringWords.sort((a, b) => a.word.localeCompare(b.word));
return highestScoringWords[0].word;
}