@vinjh3/

FaintHotpinkHaddock

JavaScript

No description

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//Compare two arrays and return a new array with any items not found in both //of the original arrays.

function diff(arr1, arr2) {
  var newArr = arr1.concat(arr2);
  
 
 var uniqueArr = newArr.filter(function (elem, pos) {
    return newArr.lastIndexOf(elem)==pos && newArr.indexOf(elem)==pos;
        
 });
 // so filter iterates over the concatenated array and test if the element is in two positions or not in the array.
 //I think this might work because lastIndexOf and index checks to see if 
 // last pos and the current pos are the same
 
  
  
  
  
  
  
  return uniqueArr;
}

diff([1, 2, 3, 5], [1, 2, 3, 4, 5]);

// need comopare the arrays against one another 
// for the sake of sanity some 
// test for the shorter array in the longer array
// call filter to return a new array with elements that

// What if we merge the the two arrays and then filter for unique values
Native Browser JavaScript