Created
May 4, 2026 01:30
-
-
Save fauxsaurus/d28ee27093c3b22b882926729c670867 to your computer and use it in GitHub Desktop.
List the number of occurrences of each glyph (character) in a string from most to least common.
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 glyphCount = (text: string) => { | |
| const glyphInstanceCount = text.split('').reduce( | |
| (sums, char) => { | |
| const {[char]: sum = 0} = sums | |
| return Object.assign(sums, {[char]: sum + 1}) | |
| }, | |
| {} as Record<string, number> | |
| ) | |
| return Object.entries(glyphInstanceCount) | |
| .sort(([_glyphA, sumA], [_gylphB, sumB]) => sumB - sumA) | |
| .map(([glyph, instanceCount]) => `"${glyph}": ${instanceCount}`) | |
| .join('\n') | |
| } | |
| // usage: glyphCount(`Embers of the Nephilim: Ghost Girl and the Ghost Giant`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment