-
Notifications
You must be signed in to change notification settings - Fork 0
/
without.js
36 lines (27 loc) · 1.12 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
const eqArrays = require('./eqArrays');
const assertArraysEqual = require('./assertArraysEqual');
//Implement without which will return a
//subset of a given array, removing unwanted elements.
// take in a source array and an itemsToRemoveArray
const without = function(source, itemsToRemove){
//return a new array with only elements from source that AREN'T in itemsToRemove
let approvedItems = [];
//loop through all items
for (let i = 0; i < source.length; i++){
//remove unwanted items
if(source[i] !== itemsToRemove[i]){
approvedItems.push(source[i]);
}
}
//if approved, push to approved array and return
console.log(approvedItems);
return approvedItems;
}
module.exports = without;
// TEST CONDITIONS
// 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"]);