-
Notifications
You must be signed in to change notification settings - Fork 0
/
without.js
59 lines (41 loc) · 1.17 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function eqArrays(val1, val2){
if(val1.length !== val2.length){
return false;
}
for(let i = 0; i < val1.length; i++){
if(val1[i] !== val2[i]){
return false;
}
}
return true;
}
function assertArraysEqual(arr1 , arr2){
if(eqArrays(arr1, arr2) === true){
return `Assertion Passed: 👍👍👍` ;
}
else{
return `Assertion Failed: 🚩🚩🚩` ;
}
}
function without(test, remove){
copyOftest = [];
for(let i = 0; i < test.length; i++){
copyOftest.push(test[i]);
}
let elemRemove = [];
for(let i = 0; i < remove.length; i++){
for(let j = 0; j < copyOftest.length; j++){
if(remove[i] === copyOftest[j]){
elemRemove.push(j);
}
}
}
for( let i = elemRemove.length - 1; i >= 0; i--){
copyOftest.splice(elemRemove[i], 1);
}
return copyOftest;
}
//without([3, 1, 3], [1]);
console.log(without([1, 2, 3], [1]));
console.log(without(["1", "2", "3"], [1, 2, "3"]));
console.log(without([5, 4, "3"], [1, 2, "3"]));