Question about filtering Multidimensional Arrays (challenge 13)


Hi all!

So, does the filter function not automatically filter every entry in a multidimensional array? Do I need to loop it through every single row?

Does this: var filteredRocks = GRID.filter(function(cell) {return cell === “^”}); only do a single row?

I don’t think I’m really understanding what’s going on here. Aaaaaahhh


Hi @Kurtillius. Look up some of the previous threads about challenge 13. Like this one:

Most participants (including me) completed the challenge using a loop, not a filter. But there is an ingenious person in that thread who used filter successfully by creating a new array of all coordinates first. And there might be some other successful strategies if you look through other threads.


To go on what @RebelBeckerton mentioned, think first what you’re given (a 2D array) and what you want the output to be (a 1D array of all the rocks). I left a link to an article in the forum post ‘Challenge 13 Filter’ and would highly recommend reading it. It gave me the insight I needed to complete Challenge 13 using the ‘map’, ‘reduce’ and ‘filter’ functions that JavaScript provides. If you have any questions, feel free to ask!


Thanks, team! I’ll take another look when I’m home from work