Last active
November 22, 2015 04:01
-
-
Save minsooshin/22e973abc4ecd247e122 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/minsooshin 's solution for Bonfire: Sorted Union
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
// Bonfire: Sorted Union | |
// Author: @minsooshin | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-sorted-union | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function unite(arr1, arr2, arr3) { | |
var args = Array.prototype.slice.call(arguments); | |
arr1 = args.reduce(function(old, cur) { | |
var obj = {}, diff; | |
for (var i = 0; i < old.length; i++) { | |
obj[old[i]] = true; | |
} | |
diff = cur.filter(function(val) { | |
return !obj[val]; | |
}); | |
return old.concat(diff); | |
}); | |
return arr1; | |
} | |
unite([1, 3, 2], [5, 2, 1, 4], [2, 1]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment