forked from anomalyco/sst
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.js
More file actions
47 lines (38 loc) · 968 Bytes
/
Copy patharray.js
File metadata and controls
47 lines (38 loc) · 968 Bytes
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
function diff(oldList, newList) {
const remove = [];
const add = [];
oldList.forEach((item) => newList.indexOf(item) === -1 && remove.push(item));
newList.forEach((item) => oldList.indexOf(item) === -1 && add.push(item));
return { add, remove };
}
function unique(arr) {
if (arr.length === 0) {
return arr;
}
const isObjArray = arr[0] instanceof Object;
arr = isObjArray ? arr.map((e) => JSON.stringify(e)) : arr;
const unique = arr.filter((e, pos) => arr.indexOf(e) === pos);
return isObjArray ? unique.map((e) => JSON.parse(e)) : unique;
}
function flatten(arr) {
return [].concat.apply([], arr);
}
function getCaseInsensitiveStringSorter() {
return (a, b) => {
const strA = a.toLowerCase();
const strB = b.toLowerCase();
if (strA < strB) {
return -1;
}
if (strA > strB) {
return 1;
}
return 0;
};
}
module.exports = {
diff,
unique,
flatten,
getCaseInsensitiveStringSorter,
};