Hi!
I’ve been following the curriculum in order and taking very detailed notes along the way, since JavaScript is the most difficult thing I’ve had to learn! (I’ve got a law degree and a Masters, yet basic JavaScript is blowing my mind!).
Anyway, I’m trying to look through the forums to really get an understanding for how this challenge works and what is being asked, but this, like a couple of others, doesn’t appear to me to request anything specific! It clearly must however, as everyone appears to understand what’s being asked - here is the challenge following the example:
" We have defined a function, filteredArray
, which takes arr
, a nested array, and elem
as arguments, and returns a new array. elem
represents an element that may or may not be present on one or more of the arrays nested within arr
. Modify the function, using a for
loop, to return a filtered version of the passed array such that any array nested within arr
containing elem
has been removed."
and here is the code:
function filteredArray(arr, elem) {
let newArr = ;
// Only change code below this line
// Only change code above this line
return newArr;
}
console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));
I’ve had to look ahead at the hints and the answer, yet I still don’t understand it! I see somewhere in the forums that someone mentions its purpose is to remove the '3’s from the nested arrays, but in the challenge description, I don’t understand where it requests that? It requests a filtered version of the nested array, but I’ve no idea by what measure we’re supposed to be filtering it.
Does the ‘elem’ declaration mean ‘how many elements there are’, which is 3 in each array? Is it the number ‘3’ that is declared after the arrays? If so to either of these, how is it known that these are specifically the elements we must remove/filter?
If anyone could break this down into human English, I’d be sincerely grateful and may even return one of the finest jokes known to all as a thank you!
Challenge: Iterate Through All an Array’s Items Using For Loops
Link to the challenge: