Created
September 19, 2020 06:52
-
-
Save hassan-maavan/a5eacf35c638f78f995016b8ef9aa582 to your computer and use it in GitHub Desktop.
Take 2 strings s1 and s2 including only letters from ato z. Return a new sorted string, the longest possible, containing distinct letters, each taken only once - coming from s1 or s2.
This file contains hidden or 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
Example: | |
// a = "xyaabbbccccdefww" | |
// b = "xxxxyyyyabklmopq" | |
// longest(a, b) -> "abcdefklmopqwxy" | |
// a = "abcdefghijklmnopqrstuvwxyz" | |
// longest(a, a) -> "abcdefghijklmnopqrstuvwxyz" | |
function longest(s1, s2) { | |
return (s1 + s2).split('').filter(onlyUnique).sort().join('') | |
} | |
function onlyUnique(value, index, self) { | |
return self.indexOf(value) === index; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment