Temir Aliev
asked on
On line 35, why did we assign var to a parameter of a function?
function findMaxRepeatCountInWord(word) {
// Break up individual words into individual letters.
var a = word.split('');
// Count the instances of each letter
var counted = a.reduce(function(allChars,char){
if (char in allChars) {
allChars[char]++;
} else {
allChars[char] = 1;
}
return allChars;
}, {});
// Iterate all the counts and find the highest
// Return this word's max repeat count
var totals = [];
for (var key in counted){
totals.push(counted[key]);
}
return totals.reduce(function(x,y) {
return (x > y) ? x : y;
});
}
function findFirstWordWithMostRepeatedChars(text) {
var maxRepeatCountOverall = 0;
var wordWithMaxRepeatCount = '';
text.split(" ").forEach(function(word) {
var repeatCountForWord = findMaxRepeatCountInWord(word);
if (repeatCountForWord > maxRepeatCountOverall) {
maxRepeatCountOverall = repeatCountForWord;
wordWithMaxRepeatCount = word;
}
});
return wordWithMaxRepeatCount;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
question is fully answered...