Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0f78c8f

Browse files
Create removeListedValues.js
1 parent fe6aff4 commit 0f78c8f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

‎Javascript/removeListedValues.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*Write a method which returns an array without the listed values
2+
3+
References
4+
Arrays
5+
6+
(MDN) JavaScript: Array
7+
8+
Nesting For Loops in JavaScript
9+
10+
Time complexity in JavaScript (Optional)
11+
12+
ArraInput -
13+
arr: The given array
14+
15+
without: A list of elements which are to be removed from arr.
16+
17+
Output -
18+
Return the array after removing the listed values.
19+
20+
Sample input 1 -
21+
arr: [1, 2, 2, 3, 1, 2]
22+
23+
without: [2, 3]
24+
25+
Sample output 1 -
26+
[1, 1]
27+
*/
28+
29+
function removeListedValues(arr, without) {
30+
var NewArr = new Array();
31+
var indexOfArray = 0;
32+
let valueMatch = false;
33+
for(let i=0; i< arr.length; i++){
34+
35+
valueMatch = false;
36+
for(let j=0; j<without.length; j++){
37+
if(arr[i] === without[j]){
38+
valueMatch = true;
39+
}
40+
}
41+
if(valueMatch== false){
42+
43+
NewArr[indexOfArray] = arr[i];
44+
indexOfArray++;
45+
}
46+
}
47+
return NewArr;
48+
}
49+
50+
module.exports = removeListedValues;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /