I have been working on this for a while now and I have no idea why this isn't working. I've read over it a few times and I can't seem to find the problem in my code.
I thought if(arr[i] === item) would check if the current element is equal to the item parameter and if true, return the index.
const lastIndexOf = (arr, item) => {
if(arr.includes(item)){
for(let i = arr.length - 1; i >= 0; i--){
if(arr[i] === item){
return i;
} else if (arr.includes(i) === false){
return Number('-1');
}
}
} else if (!arr.length){
return Number('-1');
} else {
return Number('-1');
}
}
console.log(lastIndexOf([5,5,5,5,0],5));