-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcollections.js
71 lines (60 loc) · 1.41 KB
/
collections.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function arrToSet(arr) {
return new Set(arr);
}
function arrToStr(arr) {
return arr.toString().replaceAll(",", "");
}
function setToArr(set) {
return Array.from(set);
}
function setToStr(set) {
let res = "";
set.forEach((value) => {
res += value;
});
return res;
}
function strToArr(str) {
return str.split("");
}
function strToSet(str) {
return new Set(str.split(""));
}
function mapToObj(map) {
return Object.fromEntries(map);
}
function objToMap(obj) {
return new Map(Object.entries(obj));
}
function objToArr(obj) {
return Object.values(obj);
}
function arrToObj(arr) {
return Object.assign({}, arr);
}
function strToObj(str) {
return Object.assign({}, str.split(""));
}
function superTypeOf(value) {
if (Array.isArray(value)) {
return "Array";
} else if (value instanceof Set) {
return "Set";
} else if (value instanceof Map) {
return "Map";
} else if (value === null) {
return "null";
} else if (typeof value === "object") {
return "Object";
} else if (typeof value === "string") {
return "String";
} else if (typeof value === "number") {
return "Number";
} else if (typeof value === "boolean") {
return "Boolean";
} else if (typeof value === "undefined") {
return "undefined";
} else if (typeof value === "function") {
return "Function";
}
}