Skip to content

Instantly share code, notes, and snippets.

@minsooshin
Last active November 22, 2015 04:01
Show Gist options
  • Save minsooshin/22e973abc4ecd247e122 to your computer and use it in GitHub Desktop.
Save minsooshin/22e973abc4ecd247e122 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/minsooshin 's solution for Bonfire: Sorted Union
// 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