-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwithout.js
35 lines (31 loc) · 829 Bytes
/
without.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
const eqArrays = function(array1, array2) {
var result = true ;
for(var i = 0; i <= array1.length; i++) {
if(array1[i] !== array2[i]) {
return false;
}
}
return true;
};
const assertArraysEqual = function(array1, array2) {
var result = true ;
for(var i = 0; i <= array1.length; i++) {
if(array1[i] !== array2[i]) {
result = false;
}
}
console.log(result);
};
const without = function (arr , subset){
const exclude = [...subset];
return arr.filter(x => {
const idx = exclude.indexOf(x);
if (idx >= 0) {
exclude.splice(idx, 1);
return false;
}
return true;
});
};
console.log(without([1, 2, 3], [1])); // => [2, 3]
console.log(without(["1", "2", "3"], [1, 2, "3"]) );// => ["1", "2"]