Created
August 3, 2020 23:16
-
-
Save gndelia/0d041927722bcc924adeb663f3d31ffb to your computer and use it in GitHub Desktop.
cassidoo newsletter problem solution
This file contains 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
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