You should not be pushing the elements of the sub arrays to newArr. Instead you should be pushing the entire sub array to newArr. ONLY if the sub array does not contain contain elem.
Below I have taken your current code and removed the comments and console.log statements and anything that is incorrect in your current code’s logic. In its place, I have created comments which are part of the logic you could use for code which would pass the tests.
function filteredArray(arr, elem) {
"use strict";
let newArr = [];
let len = arr.length;
for(let i = 0;i <len; i++){
// Assume that all of the elements of the subarray do not match elem (initialize a Boolean flag variable to true)
for(let j = 0;j<arr[i].length;j++){
// Check if the current element in sub array is equal to elem.
// If it is equal, then set the value of your flag variable to be false AND stop break out of loop
}
}
// If the flag variable is still true then push the sub array into newArr
}
return newArr;
}
function filteredArray(arr, elem) {
"use strict";
let newArr = [];
let len = arr.length;
for(let i = 0;i <len; i++){
/* Assume that all of the elements of the subarray do not match elem (initialize a Boolean flag variable to true)*/
if(arr[i].indexOf(elem) === -1){
return true;
}
for(let j = 0;j<arr[i].length;j++){
// Check if the current element in sub array is equal to elem.
if(arr[i][j] === 3){
return false;
break;
}
/* If it is equal, then set the value of your flag variable to be false AND stop break out of loop*/
}
}
// If the flag variable is still true then push the sub array into newArr
newArr.push(arr[i]);
console.log(newArr);
return newArr;
}
console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));
function filteredArray(arr, elem) {
"use strict";
let newArr = [];
let len = arr.length;
let value ;
for(let i = 0;i <len; i++){
/* Assume that all of the elements of the subarray do not match elem (initialize a Boolean flag variable to true)*/
if(arr[i].indexOf(elem) === -1){
value = true;
console.log(value);
}
for(let j = 0;j<arr[i].length;j++){
// Check if the current element in sub array is equal to elem.
if(arr[i][j] === elem){
value = false;
console.log(value);
break;
}
/* If it is equal, then set the value of your flag variable to be false AND stop break out of loop*/
}
if(value === true){
newArr.push(arr[i]);
}
}
// If the flag variable is still true then push the sub array into newArr
return newArr;
}
console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3));