I was expecting the result to be an array [1, 3, 1, 3], but instead it’s returning the number which was supposed to be removed. jsfiddle https://jsfiddle.net/Montinyek/a8bpuf9v/17/
The same kind of method worked fine for a slightly different problem https://jsfiddle.net/Montinyek/ty19szmL/
What gives?
function destroyer(arr, b) {
for(let i = 0; i < arr.length; i++) {
if(b === arr[i]) {
return arr.splice(i, 1)
}
}
return arr
}
console.log(destroyer([1, 2, 3, 1, 2, 3], 2));