-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution0081.js
40 lines (30 loc) · 1.1 KB
/
solution0081.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
--------------- 7 Kyu - Two to One ------------------
Instructions:
Take 2 strings s1 and s2 including only letters from a to z. Return a new sorted string, 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"
-------------
Sample Tests
describe("longest",function() {
it("Basic tests",function() {
Test.assertEquals(longest("aretheyhere", "yestheyarehere"), "aehrsty")
Test.assertEquals(longest("loopingisfunbutdangerous", "lessdangerousthancoding"), "abcdefghilnoprstu")
Test.assertEquals(longest("inmanylanguages", "theresapairoffunctions"), "acefghilmnoprstuy")
})})
--------------
Psuedo Code:
-combine strings and put into new Set
new Set(s1 + s2)
-instructions ask to return a sort()ed array
.sort()
-Set creates array of individual unique characters, so join('') them
*/
function longest(s1, s2) {
let unique = [...new Set(s1 + s2)];
return unique.sort().join('');
}