-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (30 loc) · 747 Bytes
/
index.js
File metadata and controls
35 lines (30 loc) · 747 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
function remove(array, param) {
const index = array.indexOf(param);
array.splice(index, 1);
}
function isExist(array, param) {
return array.indexOf(param) !== -1;
}
function includes(array, obj) {
var i;
for (i = 0; i < array.length; i++) {
if (array[i] === obj) {
return true;
}
}
return false;
}
module.exports = {
PureAll: function(array, inputArray) {
let newArray = array.length === 0 ? array.concat(inputArray) : [];
return newArray;
},
Pure: function(array, param) {
if (typeof param === "object") {
includes(array, param) ? remove(array, param) : array.push(param);
} else {
isExist(array, param) ? remove(array, param) : array.push(param);
}
return array;
}
};