-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathνν.js
43 lines (36 loc) Β· 874 Bytes
/
νν.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
41
42
43
// Solution 1
// μ κ·ννμμ μ¬μ©ν μ루μ
function solution1(s) {
const tuple = [];
const set = new Set();
const regex = /[^0-9]/g;
const filteredS = s
.split('},')
.map((e) => e.split(',').map((n) => Number(n.replace(regex, ''))))
.sort((a, b) => a.length - b.length);
filteredS.forEach((e) => {
e.forEach((num) => {
set.add(num);
});
});
tuple.push(...Array.from(set));
return tuple;
}
// Solution 2
// slice() λ©μλλ₯Ό μ¬μ©ν μ루μ
function solution2(s) {
const tuple = [];
const set = new Set();
const filteredS = s
.slice(2, -2)
.split('},{')
.map((e) => e.split(',').map((num) => Number(num)))
.sort((a, b) => a.length - b.length);
filteredS.forEach((e) => {
e.forEach((num) => {
set.add(num);
});
});
tuple.push(...Array.from(set));
return tuple;
}