-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwithout.js
43 lines (37 loc) · 1.14 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
let eqArrays = function(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;
};
let assertArraysEqual = function(arOne, arTwo) {
if (eqArrays(arOne, arTwo) === true) {
console.log(`✅✅✅Assertion Passed: ${arOne} === ${arTwo}`);
} else {
console.log(`🛑🛑🛑Assertion Failed: ${arOne} !== ${arTwo}`);
}
};
let without = function(source, itemsToRemove) {
let newItems = [];
for (let i = 0; i < source.length; i++) {
if (itemsToRemove.indexOf(source[i]) < 0) {
newItems.push(source[i]);
}
}
return newItems;
}
/*
assertArraysEqual(without([1, 2, 3], [1]), [2, 3]) // => [2, 3]
assertArraysEqual(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"]);
//checking to see it this works pls
*/
module.exports = without;