Created
October 13, 2020 16:53
-
-
Save ifkas/76a02da9a703ec898eec45fd07118f52 to your computer and use it in GitHub Desktop.
Reduce - exercise two 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 longest(s1, s2) { | |
const allLetters = s1 + s2; | |
const distinctLetters = allLetters.split('').reduce((distinctLetters, currentLetter) => { | |
distinctLetters[currentLetter] = true; | |
return distinctLetters; | |
}, {}); | |
const letters = Object.keys(distinctLetters); | |
return letters.sort().join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment