Created
October 14, 2017 18:53
-
-
Save hadijaveed/86251df37700527f5c70e70dff66b209 to your computer and use it in GitHub Desktop.
Find missing element from 2nd Array
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
function differenceFromSecondArray(arr1, arr2) { | |
let arr1Map = arr1.reduce((acc, curr) => { | |
return { ...acc, [curr]: 1 } | |
}, {}) | |
return arr2.reduce((acc, curr) => arr1Map.hasOwnProperty(curr) ? acc : acc.concat(curr), []) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment