I just did a coding challenge where I had to remove all non numberic items from an array without creating a new array which means no map
or filter
.
I didn't do that great because I was trying to splice
but I'd lose my index.
What is a nice way of doing this?
const filterNums = (nums) => {
for (let item in nums) {
if (typeof nums[item] !== 'number') {
// Remove item
}
}
return nums;
};
console.log(filterNums([1, 'a', 2, 'b', true]));