-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathremoveListedValues.js
50 lines (36 loc) · 949 Bytes
/
removeListedValues.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
44
45
46
47
48
49
50
/*Write a method which returns an array without the listed values
References
Arrays
(MDN) JavaScript: Array
Nesting For Loops in JavaScript
Time complexity in JavaScript (Optional)
ArraInput -
arr: The given array
without: A list of elements which are to be removed from arr.
Output -
Return the array after removing the listed values.
Sample input 1 -
arr: [1, 2, 2, 3, 1, 2]
without: [2, 3]
Sample output 1 -
[1, 1]
*/
function removeListedValues(arr, without) {
var NewArr = new Array();
var indexOfArray = 0;
let valueMatch = false;
for(let i=0; i< arr.length; i++){
valueMatch = false;
for(let j=0; j<without.length; j++){
if(arr[i] === without[j]){
valueMatch = true;
}
}
if(valueMatch== false){
NewArr[indexOfArray] = arr[i];
indexOfArray++;
}
}
return NewArr;
}
module.exports = removeListedValues;