Debugging-wise, you want to see if there are any errors in the console itself. If you’re in Chrome, open the developer console, run the tests, then see if there are any errors there, first. You may see something like the following:
transformers.js:85 TypeError: unknown: Cannot read property '0' of undefined
at Function.e.get (babel.js:3632)
at e.h [as unshiftContainer] (babel.js:42437)
You can actually copy/paste your function into the console, then copy/paste the console.log statement above to see what the output is. As it turns out, it works in the console, so the problem may be in how the FCC code is running the function.
As it turns out, the problem seems to be with
for(let j=0; j < arr[j].length; ++j)
if(arr[i][j] != elem){
subArr.push(arr[i][j]);
}
newArr.push(subArr);
Although this should work, apparently the FCC code doesn’t like that the for loop doesn’t surround the if block with brackets, i.e.,
function filteredArray(arr, elem) {
//debugger;
let newArr = [];
// change code below this line
for (let i=0; i<arr.length;i++){
let subArr=[];
for(let j=0; j < arr[j].length; j++) **{**
if(arr[i][j] != elem) subArr.push(arr[i]);
**}**
newArr.push(subArr);
}
// change code above this line
return newArr;
}
Once you get past that, however, you’ll find that your solution doesn’t pass the tests. You want to remove arrays that contain the second argument, not remove the second argument from each array, e.g., one example from the tests is below:
‘’’
filteredArray([[10, 8, 3], [14, 6, 23], [3, 18, 6]], 18) should return [ [10, 8, 3], [14, 6, 23] ]
‘’’
P.S. — The debugger statement in the function that I’ve commented out allows you to stop at that point in the function and use the Chrome developer tools to step thru the function to see how it behaves. There’s a lot that you can do in the developer tools, so it’s worthwhile to play with those features and see how things work, if you haven’t already.