Tell us what’s happening:
Your code so far
function filteredArray(arr, elem) {
let newArr = [];
// change code below this line
// change code above this line
return newArr;
}
// change code here to test different cases:
console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-all-an-arrays-items-using-for-loops
The function takes 2 arguments arr & elem
The function should search arr which is a nested array (an array of arrays) and remove any array that contains elem
In that example:
[[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]] is the arr
3 is the elem
3 is within all four arrays and therefore all four arrays are removed and the function should return an empty array []
HI @omkarkothavale88 Please note that the function have one parameter call elem, that param define on the list of the arrays whats element does not return, Said in another words, if this elem is on the array, the array doesn’t assign in the new var newArr.
still scratching my head…plz make it simpler
In the case of the first test
filteredArray([[10, 8, 3], [14, 6, 23], [3, 18, 6]], 18) should return [ [10, 8, 3], [14, 6, 23] ]
You have this array (arr) [[10, 8, 3], [14, 6, 23], [3, 18, 6]]
and this number (elem) 18
Iterate (loop) through arr. Any of arr that does not contain elem get puts into newArr.
[10, 8, 3] does not contain 18 so it goes into newArray
[14, 6, 23] does not contain 18 so it goes into newArray
[3, 18, 6] contains 18 so it does not go into newArray
return newArray[ [10, 8, 3], [14, 6, 23] ]