I wanted to know how I get the last element of the array using the structure for
in the case for decrement?
My code is this:
const a = n => n % 2 === 0;
function callbackfn (valorInserido, funcao) {
for (valorInserido.length; i=0; i--) {
if (funcao(valorInserido[i])) {
return valorInserido[i];
}
}
}
console.log(callbackfn([3,5,2,4],(a)));
In case it was to return the number 4
, however it returns undefined
.