Skip to content

Instantly share code, notes, and snippets.

@sharmaabhinav
Created November 6, 2017 09:48
Show Gist options
  • Save sharmaabhinav/944a00a636996b50ebc6dd86b19b6450 to your computer and use it in GitHub Desktop.
Save sharmaabhinav/944a00a636996b50ebc6dd86b19b6450 to your computer and use it in GitHub Desktop.
const union = (arr1, arr2) => utility.uniq([...arr1, ...arr2])
var utility = {union, uniq}
function uniq (arr) {
var elemMap = {}
for(var val of arr){
elemMap[val] = elemMap[val] ? elemMap[val] += 1 : 1
}
return Object.keys(elemMap).map(function (key) {
return Number(key)
})
}
console.log(utility.union([1,3,7,8], [1,3,4,5]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment