Skip to content

Instantly share code, notes, and snippets.

@fauxsaurus
Created May 4, 2026 01:30
Show Gist options
  • Select an option

  • Save fauxsaurus/d28ee27093c3b22b882926729c670867 to your computer and use it in GitHub Desktop.

Select an option

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.
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