//alter the remove function so that it removes all occurrences of an item from a list.
function remove(item, l) {
if (l.length === 0) {
return [];
} else if (item === l[0]) {
return l.slice(1);
} else {
return [l[0], remove(item, l.slice(1))];
}
}
console.log(remove("c", ["a", "c", "b", "c", "d"])); //should be ['a', 'b', 'd']
//simplify this remove function with JavaScript's built-in array method filter
function remove(item, l) {
if (l.length === 0) {
return [];
} else if (item === l[0]) {
return l.slice(1);
} else {
return [l[0], remove(item, l.slice(1))];
}
}
console.log(remove("c", ["a", "c", "b", "c", "d"])); //should be ['a', 'b', 'd']