-
Notifications
You must be signed in to change notification settings - Fork 0
/
without.js
46 lines (39 loc) · 967 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
36
37
38
39
40
41
42
43
const assertArraysEqual = (arr1, arr2) => {
let result = true;
if (arr1.length !== arr2.length) {
result = false;
}
for (let i = 0; i < arr1.length; i++) {
if (arr1[i] !== arr2[i]) {
result = false;
}
}
if (result) {
console.log(`✅✅✅ ${arr1} matches ${arr2} ✅✅✅`);
} else {
console.log(`🛑🛑🛑 ${arr1} does not match ${arr2} 🛑🛑🛑`);
}
};
const eqArrays = (arr1, arr2) => {
if (arr1.length !== arr2.length) {
return false;
}
for (let i = 0; i < arr1.length; i++) {
if (arr1[i] !== arr2[i]) {
return false;
}
}
return true;
};
const without = (srcArr, itemsToRemove) => {
let resultArr = [...srcArr]
for (let i = 0; i < itemsToRemove.length; i++) {
const foundIndex = resultArr.indexOf(itemsToRemove[i]);
if (foundIndex > -1) {
//.log(resultArr);
resultArr.splice(foundIndex, 1);
}
}
return resultArr;
}
module.exports = without;