You’re supposed to return the new filtered array but your code returns the original, unmodified array instead.
This line does not modify the arr array at all; it returns a new array that is never used elsewhere.
So here’s what you should do. To make things simple, you don’t need nested for loops. Use only one for loop, and use the .includes()array method to check if an element exists within an array. Modify the newArr variable as needed and then return it.
sorry @asemarian but your explanation is not correct
splice mutate the original array, and that’s the issue: if you mutate the array you are iterating over you have unexpected results, like some elements not getting tested, loop stopping prematurely etc
also splice returns the removed elements from the array
@tejambsnks instead of using splice , try to use a different method to add the elements you want to keep to newArr