Skip to content

Instantly share code, notes, and snippets.

@mkamakura
Created October 16, 2023 13:15
Show Gist options
  • Save mkamakura/1db92fdf69d616bb0d7495c1304c26f8 to your computer and use it in GitHub Desktop.
Save mkamakura/1db92fdf69d616bb0d7495c1304c26f8 to your computer and use it in GitHub Desktop.
function diff(arr1: number[], arr2: number[]) {
const uniqueArr1 = arr1.filter(a1 => !arr2.includes(a1))
const uniqueArr2 = arr2.filter(a2 => !arr1.includes(a2))
return [...uniqueArr1, ...uniqueArr2]
}
const test1 = [[1,4,3,7],[3,4,5]]
console.log(diff(test1[0], test1[1]))
const test2 = [[1,4,3,7],[3,4,5],[5]]
console.log(test2.reduce((pre, cur) => diff(pre, cur), []))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment