Created
November 2, 2022 21:31
-
-
Save muriukialex/0c8415cef466c810a606bbd427a59a60 to your computer and use it in GitHub Desktop.
Different Item between Two Arrays
This file contains hidden or 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
let differentItems = (arr1, arr2) => { | |
let set = new Set() | |
let res = [] | |
let leastArray = arr1.length <= arr2.length ? arr1 : arr2 | |
let largestArray = arr1.length >= arr2.length ? arr1 : arr2 | |
for(let i=0; i < leastArray.length; i++){ | |
set.add(leastArray[i].id) | |
} | |
for(let i=0; i < largestArray.length; i++){ | |
if(!set.has(largestArray[i].id)){ | |
res.push(largestArray[i]) | |
} | |
} | |
return res | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment