/*
***If all the elements match, it should return an empty array.
***If an empty array is passed in, it should return an empty
array.
*/
function removeElement(array, discarder) {
if(array.length === 0) {
array = [];
}
for(var i=0; i<array.length; i++) {
if(discarder === array[i]) {
array.splice(i, 1);
}
return array;
}
}
var output = removeElement([1, 2, 3, 2, 1], 2);
console.log(output); // --> [1, 3, 1]
Does anyone know how I can delete an array element I specify in the discarder argument?
Also, I need to return an empty Array if all elements are the same. I've been stuck on this for way too long.