Last active
June 14, 2018 03:07
-
-
Save drldcsta/38ad052a1bc92cbc57ba6f64025618bf to your computer and use it in GitHub Desktop.
Highest Scoring Word
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
Solution for https://www.codewars.com/kata/highest-scoring-word/train/javascript | |
const high = (wordsString) => { | |
const words = wordsString.split(" ") | |
const alphabet = 'abcdefghijklmnopqrstuvwxyz'.split(''); | |
let scores = [] | |
let maxScore = 0 | |
let maxScoreIndex | |
words.forEach(word => { | |
let letters = word.split('') | |
let score = 0 | |
letters.map((letter) => { | |
score += (alphabet.indexOf(letter.toLowerCase()) + 1) | |
}) | |
// console.log(score); | |
scores.push(score) | |
}); | |
// console.log(scores) | |
for (let score in scores) { | |
if (scores[score] > maxScore) { | |
maxScore = scores[score] | |
maxScoreIndex = score | |
} | |
scores[score] = `word : ${words[score]}, score : ${scores[score]}` | |
} | |
console.log(scores) | |
return words[maxScoreIndex] | |
} | |
console.log(high('man i need a taxi up to ubud')) | |
console.log(high('what time are we climbing up the volcano')) | |
console.log(high('take me to semynak')) | |
console.log(high("xxa jaaajj")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment