I don’t understand why this is working for the first 5 tests but not the last three. Could someone please explain the issue?
function diffArray(arr1, arr2) {
var newArr = [];
for (var i = 0; i < arr1.length && i < arr2.length; i++)
if (arr2.indexOf(arr1[i]) == -1) {
newArr.push(arr1[i]);
}
else if (arr1.indexOf(arr2[i]) == -1) {
newArr.push(arr2[i]);
}
return newArr;
}
diffArray([1, "calf", 3, "piglet"], [7, "filly"]);