Skip to content

Instantly share code, notes, and snippets.

@frewsxcv
Forked from markjanzer/LetterCountI
Created June 29, 2015 21:45
Show Gist options
  • Save frewsxcv/0ec6b468228d0ed524b7 to your computer and use it in GitHub Desktop.
Save frewsxcv/0ec6b468228d0ed524b7 to your computer and use it in GitHub Desktop.
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