Last active
July 16, 2024 08:31
-
-
Save jonrandy/6103c00128faf009812dce26019b1860 to your computer and use it in GitHub Desktop.
Most common char in string JS
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 mostFrequent = s=>s.match(/(.)\1+/g)?.sort((a,b)=>b.length-a.length)[0][0]||s[0] | |
const mostFrequentLetter = s=>([...s].sort().join('').match(/(\w)\1+/g)?.sort((a,b)=>b.length-a.length)[0]||s.match(/\w/))[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment