Skip to content

Instantly share code, notes, and snippets.

@drldcsta
Last active June 14, 2018 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drldcsta/38ad052a1bc92cbc57ba6f64025618bf to your computer and use it in GitHub Desktop.
Save drldcsta/38ad052a1bc92cbc57ba6f64025618bf to your computer and use it in GitHub Desktop.
Highest Scoring Word
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