I have to write a single function in javascript.
- Takes in a string (full sentence).
- Analyzes which words have the highest count of repeated letters (i.e. rabbit, happy, there, etc).
- Repeated letters don't have to be consecutive.
- Returns the one (or more if there is a tie) word(s) that had highest repeated letter count in array format.
Example:
console.log(letterRepeat("Hello there Mr. Gormoon!));
Output:
{Gormoon}
So far I have created a function that will first split words, then letters:
var wordSelector = function(str){
var wordArray = [];
wordArray.push(str.split(" ").map(function(word) {
return word.split("");
}));
return wordArray[0];
};
console.log(wordSelector("Hello there Mr. Gormoon!"));
Output:
[["H", "e", "l", "l", "o"], ["t", "h", "e", "r", "e"], ["M", "r", "."], ["G", "o", "r", "m", "o", "o", "n", "!"]]
So far I have had a strong idea of what needed to be done, but I am not sure how to count each letter per word then identify the max?
But once I count them, I can sort them and take the one at position wordArray[0]