-
Notifications
You must be signed in to change notification settings - Fork 0
/
without.js
35 lines (30 loc) · 852 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
const eqArrays = function(arrA, arrB) {
if (arrA.length !== arrB.length) {
return false;
}
for (let i = 0; i < arrA.length; i++) {
if (arrA[i] !== arrB[i]) {
return false;
}
}
return true;
};
const assertArraysEqual = function(arrA, arrB) {
if (eqArrays(arrA, arrB)) {
console.log(` 😀 Assertion Passed: ${arrA} === ${arrB}`);
} else {
console.log(` 😈 Assertion Failed: ${arrA} !== ${arrB}`);
}
};
const without = function(sourceArray, itemsToRemove) {
let newArray = [];
for (let i = 0; i < sourceArray.length; i++) {
for (let j = 0; j < itemsToRemove.length; j++) {
if (sourceArray[i] !== itemsToRemove[j]) {
newArray.push(sourceArray[i]);
}
}
}
return newArray;
};
assertArraysEqual(without(["apple", "orange", "banana"], ["banana"]), ["apple", "orange"]);