Skip to content

Instantly share code, notes, and snippets.

@muriukialex
Created November 2, 2022 21:31
Show Gist options
  • Save muriukialex/0c8415cef466c810a606bbd427a59a60 to your computer and use it in GitHub Desktop.
Save muriukialex/0c8415cef466c810a606bbd427a59a60 to your computer and use it in GitHub Desktop.
Different Item between Two Arrays
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