-
Notifications
You must be signed in to change notification settings - Fork 0
/
without.js
37 lines (32 loc) · 1.09 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
const eqArrays = function(num1, num2) {
let newNum1 = num1;
let newNum2 = num2;
if (num1.toString() === num2.toString()) {
console.log(newNum1 + " === " + newNum2);
return true;
} else {
console.log(newNum1 + " !== " + newNum2);
return false;
}
};
const assertArraysEqual = function(bool) {
if (bool === true) {
console.log("Assertation Passed: These arrays are the same!");
} else {
console.log("Assertation Failed: These arrays are different!");
}
};
const without = function(sourceArray, itemsToRemove) {
let newArray = sourceArray.filter(i => {
return !itemsToRemove.includes(i);
});
console.log(newArray);
return newArray;
};
without([1, 2, 3], [1]); // => [2, 3]
without(["1", "2", "3"], [1, 2, "3"]); // => ["1", "2"]
const words = ["hello", "world", "lighthouse"];
without(words, ["lighthouse"]); // no need to capture return value for this test case
// Make sure the original array was not altered by the without function
assertArraysEqual(words, ["hello", "world", "lighthouse"]);
assertArraysEqual(eqArrays(words, ["hello", "world", "lighthouse"]));