Created
October 16, 2023 13:15
-
-
Save mkamakura/1db92fdf69d616bb0d7495c1304c26f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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