Created
October 17, 2021 18:26
-
-
Save lior-amsalem/2be51e91d51627d41eda32521b9f6bb4 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
/** | |
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