-
Notifications
You must be signed in to change notification settings - Fork 0
/
without.js
53 lines (36 loc) · 1.03 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
const eqArrays = function (array1, array2){
if (array1.length !== array2.length) {
return false;
}
for (let i = 0; i < array2.length; i++) {
if (array1[i] !== array2[i]){
return false;
}
}
return true;
};
const assertArraysEqual = function (actual, expected){
if (eqArrays(actual, expected)) {
console.log(` ✅ Assertion Passed: ${actual} === ${expected}`);
} else {
console.log(` 🔴 Assertion Failed: ${actual} !== ${expected}`);
}
};
//assertArraysEqual([1, 2, 3], [1, 2, 3]);
const without = function (source, itemsToRemove){
let newArray = [];
for(let i = 0; i < source.length; i++){
let shouldWePush = true;
for (let j = 0; j < itemsToRemove.length; j++){
if (source[i] === itemsToRemove[j]){
shouldWePush = false;
}
}
if(shouldWePush) {
newArray.push(source[i]);
}
}
return newArray;
}
console.log(without([1, 2, 3,4,5,6,7], [1,2,6, 5])) // => [2, 3]
assertArraysEqual(without([1, 2, 3,4,5,6,7], [1,2,6, 5],4),[3,4 ,7])