Trying to get this code to output -1 when value never occurs in an array.
function IndexOf (array,value) {
var index = [];
for (var i = 0; i < array.length; i++)
if (array[i] === value) {
index.push(i);
return index.pop();
} else if (value === undefined) {
return -1;
}
}
EDIT: not allowed to use .indexOf for this particular case.
EDIT 2: Sorry I wasn't more clear. I need to return the last matched element as opposed to first.