Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
LetterCountI
function LetterCountI(str) {
str = str.split(" ");
var answer = "";
var mostRep = 1;
for (i = 0; i < str.length; i++)
if (eachWord(str[i]) > mostRep) {
mostRep = eachWord(str[i]);
answer = str[i];
}
if (mostRep === 1)
return -1;
else
return answer;
}
function eachWord(string) {
string = string.toLowerCase().split("").sort();
var counter = 1;
var most = 1;
for (i = 1; i < string.length; i++) {
if (string[i] === string[i - 1])
counter++;
else
if (counter > most) {
most = counter;
counter = 1;
}
if (i === string.length - 1)
if (counter > most)
most = counter;
}
return most;
}
console.log(LetterCountI("heey brew"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.