Created
September 6, 2022 13:18
-
-
Save mauriciord/ead954b3910ed2f22e79c8adb4320075 to your computer and use it in GitHub Desktop.
Highest in a string
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 s = 'abcergsserswsGiogjadSf48ewfu64896' | |
const listByKey = Array.from(s).reduce((acc, char) => { | |
if (!isNaN(char)) return acc | |
const letter = char.toLowerCase() | |
const count = acc[letter] ? acc[letter] + 1 : 1 | |
return { | |
...acc, | |
[letter]: count | |
} | |
}, {}) | |
const highest = Object.keys(listByKey).reduce((a, b) => listByKey[a] > listByKey[b] ? a : b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment