Skip to content

Instantly share code, notes, and snippets.

@ifkas
Created October 13, 2020 16:53
Show Gist options
  • Save ifkas/76a02da9a703ec898eec45fd07118f52 to your computer and use it in GitHub Desktop.
Save ifkas/76a02da9a703ec898eec45fd07118f52 to your computer and use it in GitHub Desktop.
Reduce - exercise two solution
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