Hello everybody,
working on the session ‘iterate through all array’s elements using a for loop’, this is my question: if the exercise was about sub-arrays in one array, plus the ‘elem’ item, why to iterate through them is not needed a double for loop??
for (let i=0;i<arr.length;i++){
if(arr[i].indexOf(elem)<0){
newArr.push(arr[i]);
You used a double loop though
You didn’t “write” two loops, but what do you think .indexOf(elem) does? It loops over an array to find the index. So someone else has written the second loop, but you are using it, by calling the method.
I’m going back to edit my prior posts to avoid confusion for folks that come after.
I’m a dunce. I DID misunderstand the intended outcome of the project that it was removing the ELEMENTS that matched the elem value. I am now clear that it is removing the ENTIRE SUBARRAY if it finds that value anywhere in the subarray.
Full ownership for the confusion. I appreciate your patience.