function diffArray(arr1, arr2) {
var newArr = [];
var newValue;
var result = [];
var indexx;
newArr=arr1.concat(arr2);
for(var i=0; i<newArr.length; i++) {
newValue = newArr[i].valueOf();
indexx = newArr.indexOf(newValue, i+1); //on first iteration indexx === 4 but it still goes into if and pushes the value in result
//console.log(indexx);
if (indexx === -1) {
return result.push(newValue);
}
}
}
We are given two arrays. The program is looking for item that only found in on of the arrays and should return it. So the question is. Why is it entering 'If' even when statement is incorrect. See comments in the code.
Aucun commentaire:
Enregistrer un commentaire