-
Notifications
You must be signed in to change notification settings - Fork 0
/
without.js
40 lines (34 loc) · 1.04 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
const eqArrays = function(arr1, arr2) {
if (arr1.length !== arr2.length) {
return false;
} else {
for (let i = 0; i < arr1.length; i++) {
if (arr1[i] === arr2 [i]) {
continue;
} else {
return false;
}
}
} return true;
};
const assertArraysEqual = function(data1, data2) {
let isEqual = eqArrays(data1, data2);
let expected = true;
if (isEqual === expected) {
return (`✅ Assertion Passed: ${isEqual} === ${expected}`);
} else {
return (`❌ Assertion Failed: ${isEqual} !== ${expected}`);
}
};
const without = function(source, itemToRemove) {
for (let i = 0; i < itemToRemove.length; i++) {
let newArr = source.filter((item)=> item !== itemToRemove[i]);
source = newArr;
} return source;
};
const words = ["hello", "world", "lighthouse"];
console.log(without(words, ["lighthouse"]));
console.log(assertArraysEqual(words, ["hello", "world", "lighthouse"]));
console.log(without([1, 2, 3], [1]));
console.log(without(["1", "2", "3"], [1, 2, "3"]));
module.exports = without;