I'm trying to remove elements that are the same i.e removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
const removeFromArray = function(numbers, ...valuesToCheck) {
for(i=0; i<numbers.length; i++){
for(j=0; j<valuesToCheck.length; j++){
if(numbers[i] == valuesToCheck[j]) {
const index = numbers.indexOf(valuesToCheck[j]);
numbers.splice(index, 1);
i--;
}
}
}
return numbers;
};
The code works when numbers are entered, however when a string is entered i.e removeFromArray([1,2,3,4], "3", 2);
, the return on the function doesn't make sense to me. I want to have it so that only numbers will prompt the corresponding number in the array to be removed and other data types such as strings won't have any effect.
Any hints would be appreciated.
Thank you.