Last active
June 24, 2019 11:14
-
-
Save olaysco/160b942dcb0e4d2c958bbde4e24db1a4 to your computer and use it in GitHub Desktop.
Javascript function to substract Arrays of Object A from Arrays of Object B (A-B) i.e. getting the differences between two Arrays of Object
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
/** | |
* this function assumes array A and array B have an id key in | |
* each of their object | |
**/ | |
function subtractArray(arrayA, arrayB){ | |
return arrayA.filter((aElem)=>{ | |
return !arrayB.find(bElem=>bElem.id === aElem.id) | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment