Created
November 6, 2017 09:48
-
-
Save sharmaabhinav/944a00a636996b50ebc6dd86b19b6450 to your computer and use it in GitHub Desktop.
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
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