Last active
August 12, 2019 16:11
-
-
Save violet-athena/581b499ccfe62cf960c9f56b11b4baea to your computer and use it in GitHub Desktop.
Find the the most frequent character 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 getCharacterFrequency = string => string.split('').reduce((acc, char) => { | |
const { length } = string.split(char); | |
if (length > acc.frequency) { | |
acc.frequency = length; | |
acc.mostFrequent = char; | |
} | |
return acc; | |
}, { frequency: 0, mostFrequent: '' }).mostFrequent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment