I searched among many similar questions, but was unable to find a answer to this tricky one. I need a function that removes all the items that are not numbers from the array. But function should modify existing array, not create a new one. I tried to do something like this:
let array = [1, 'a', 'b', 2];
array = array.filter(item => typeof item !== "string");
console.log(array);
//--> [1, 2]
While I am getting the right result I fell the test on additional points, because according to MDN the result creates a new array with the right result, which I was neglected and not knew completely.
So does anyone have the more experience than me in solving these, from the point of my thoughts I am trying to do something for hours with array.splice and for loops, but nothing near successful.Thank you in advance, and sorry for the long opening post.
Array#splice()if requirements are that specific then. Realistically what you have done makes sense as it is if you don't need any of the other data in the future