1function diffArray(arr1, arr2) {
2 return arr1
3 .concat(arr2)
4 .filter(item => !arr1.includes(item) || !arr2.includes(item));
5}
1function arrayDiff (a1, a2) {
2 var a = [], diff = [];
3 for (var i = 0; i < a1.length; i++) {
4 a[a1[i]] = true;
5 }
6 for (var i = 0; i < a2.length; i++) {
7 if (a[a2[i]]) {
8 delete a[a2[i]];
9 } else {
10 a[a2[i]] = true;
11 }
12 }
13 for (var k in a) {
14 diff.push(k);
15 }
16 return diff;
17}
18//usage:
19console.log(arrayDiff(['red', 'white','green'], [ 'red','white', 'blue']));//["green", "blue"]
1var array1 = [1,2,3,4,5,6.25];
2var array2 = [9,8,7,6,5,4];
3
4const diffNumber = (arr1, arr2) => arr1.map(function (num, idx) { return num- arr2[idx] });
5
6diffNumber(array2, array1); //[8, 6, 4, 2, 0, -2.25]