I have two arrays for example
a1 = ["1","2","7","7"];
a2 = ["1","2","7"];
I have to write function in plain javascript to find diferrences . I do not have any streams, list etc..
My code is
lastproducts = new List();
for (var i = 0; i < a1.length; i++) {
if (a2.indexOf(a1[i]) == -1) {
lastproducts.insertIntoList(lastproducts.listLength,a1[i])}
}
return lastproducts;
}
The problem is that this code doesn't know the difference. I'd like you to spot a duplicate, and return in this case "7" ;
Can You help me ? Thank You