Instructions:
Take 2 strings s1 and s2 including only letters from a to z. Return a new sorted string (alphabetical ascending), the longest possible, containing distinct letters - each taken only once - coming from s1 or s2.
Examples:
a = "xyaabbbccccdefww"
b = "xxxxyyyyabklmopq"
longest(a, b) -> "abcdefklmopqwxy"
a = "abcdefghijklmnopqrstuvwxyz"
longest(a, a) -> "abcdefghijklmnopqrstuvwxyz"
Thoughts:
- First I transform both of the strings to an array and sort them, so the array will be in an alphabetical order.
- I wrap the array into a set to eliminate the duplication and after the set is spread, I join it to the final string.
This is a CodeWars Challenge of 7kyu Rank (https://www.codewars.com/kata/5656b6906de340bd1b0000ac/javascript)
Top comments (0)