Skip to content

Instantly share code, notes, and snippets.

@mauriciord
Created September 6, 2022 13:18
Show Gist options
  • Save mauriciord/ead954b3910ed2f22e79c8adb4320075 to your computer and use it in GitHub Desktop.
Save mauriciord/ead954b3910ed2f22e79c8adb4320075 to your computer and use it in GitHub Desktop.
Highest in a string
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