Created
May 16, 2018 18:23
-
-
Save alexko30/0fadea06ac927f3892c7b1187eedaac9 to your computer and use it in GitHub Desktop.
scoreWords.js
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
function scoreWords(sentence) { | |
sentence = sentence.split(' '); | |
let amountOfLetters = 0, | |
currentCounter = 0, | |
endCounter = 0, | |
index; | |
sentence.forEach((x, i) => { | |
x.split('').forEach(y => { | |
currentCounter++ | |
}); | |
if (currentCounter > endCounter) { | |
endCounter = currentCounter; | |
index = i; | |
} | |
}); | |
console.log(index); | |
} | |
scoreWords('Hello, I am Alex, and I am from Ukraine'); // 8 index - longest item | |
scoreWords('1234, 123456, 12345678912345 1234567890'); // 3 index - longest item |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment