Skip to content

Instantly share code, notes, and snippets.

@gndelia
Created August 3, 2020 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gndelia/0d041927722bcc924adeb663f3d31ffb to your computer and use it in GitHub Desktop.
Save gndelia/0d041927722bcc924adeb663f3d31ffb to your computer and use it in GitHub Desktop.
cassidoo newsletter problem solution
function charNumSort(array) {
return array
.map((word) => ({ word, characters: new Set(word.toLowerCase().split('')) }))
.sort((a, b) => {
if (a.characters.size === b.characters.size) {
return b.word.length - a.word.length
}
return a.characters.size - b.characters.size
})
.map(({ word }) => word)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment