Last active
September 15, 2018 18:45
-
-
Save jordanhudgens/0e135c1d6163ddf5ed0521243cc3db22 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const maxStringCounter = str => { | |
const obj = {}; | |
const splitStr = str.split("").filter(el => el !== " "); | |
splitStr.forEach(el => { | |
if (obj[el]) { | |
return (obj[el] += 1); | |
} else { | |
return (obj[el] = 1); | |
} | |
}); | |
const values = Object.values(obj); | |
const keys = Object.keys(obj); | |
const maxValue = Math.max(...values); | |
const indexOfLargestValue = values.indexOf(maxValue); | |
return keys[indexOfLargestValue]; | |
}; | |
maxStringCounter("44123"); // 4 | |
maxStringCounter("441111123"); // 1 | |
maxStringCounter("Some brown and blue fox"); // o |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment