-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwithout.js
More file actions
36 lines (28 loc) 路 1.23 KB
/
Copy pathwithout.js
File metadata and controls
36 lines (28 loc) 路 1.23 KB
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
const assertArraysEqual = function(arrayOne, arrayTwo) {
if (arrayOne.length !== arrayTwo.length) return false;
for (let i=0; i < arrayOne.length; i++) {
if (arrayOne[i] !== arrayTwo[i]) return false;
}
return true;
console.log(`馃毄Assertion Failed: ${actual} !== ${expected}`);
};
const eqArrays = function(arrayOne, arrayTwo) {
if (arrayOne.length !== arrayTwo.length) return false;
for (let i=0; i < arrayOne.length; i++) {
if (arrayOne[i] !== arrayTwo[i]) return false;
}
return true;
};
const without = function(source, itemsToRemove) {
let newArray = [];
for (let i = 0; i < source.length; i++) {
if (itemsToRemove.includes(source[i])) continue;
newArray.push(source[i]);
}
return newArray;
};
// assertArraysEqual(without([1, 2, 3], [1]),[2, 3])
// assertArraysEqual(without(["1", "2", "3"], [1, 2, "3"]),["1", "2"])
//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