Skip to content

Instantly share code, notes, and snippets.

@sweeneyapps
Created July 6, 2021 05:50
Show Gist options
  • Save sweeneyapps/3db43c76a81d0f9cb65be017806997d4 to your computer and use it in GitHub Desktop.
Save sweeneyapps/3db43c76a81d0f9cb65be017806997d4 to your computer and use it in GitHub Desktop.
let _ = require('lodash');
let arr = [1, 5, 10];
let arr2 = [1, 4, 10];
let result = _.difference(arr, arr2); // 5
let result2 = _.difference(arr2, arr); // 4
let diffTogether = [...result, ...result2]; // [ 5, 4 ]
let newSet = new Set([...arr, ...arr2]); // Set(1, 4, 5, 10)
let matched = _.difference([...newSet], diffTogether); // [ 1, 10 ]
console.log(matched); // [ 1, 10 ]
console.log(diffTogether); // [ 5, 4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment