Why in this code the last element of the array passed to the function inArray ([1,2,3,4,5]) is not added to the result array? But if you add any other element to the end of the array, the result will be correct (result = [3,4,5]).
function inArray(array) { return function (currentArray) { var result = []; for (var i = 0; i < currentArray.length; ++i) { if (currentArray[i] in array ) result.push(currentArray[i]); } return result ; } } var a = inArray([1,2,3,4,5])([3,5,4]); // result = 3,4 alert(a);
[1,2,3,4,5]with indices 3, 4, hence the absence of 5 (since the last index is 4). - MedvedevDev