Skip to content

Instantly share code, notes, and snippets.

@lior-amsalem
Created October 17, 2021 18:26
Show Gist options
  • Save lior-amsalem/2be51e91d51627d41eda32521b9f6bb4 to your computer and use it in GitHub Desktop.
Save lior-amsalem/2be51e91d51627d41eda32521b9f6bb4 to your computer and use it in GitHub Desktop.
/**
Developer comment
- This is a difference function, which subtracts one list from another and returns the result.
- we'll go over all 'b' values
- we'll use filter to knock down each of 'b' values from 'a' array
**/
function arrayDiff(a, b) {
let newArray = a;
if(a.length === 0 || b.length === 0){
return a || []
}
b.map((val) => {
newArray = newArray.filter((aValue) => aValue !== val);
});
return newArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment