Skip to content

Instantly share code, notes, and snippets.

@jeremiahbiard
Created June 15, 2015 20:51
Show Gist options
  • Save jeremiahbiard/eef39c98d0b4cfefd2bd to your computer and use it in GitHub Desktop.
Save jeremiahbiard/eef39c98d0b4cfefd2bd to your computer and use it in GitHub Desktop.
Solution to the symmetric difference bonfire. I love functional programming.
function complement(A, B) {
return A.filter(function(elem) { return B.indexOf(elem) == -1; });
}
function unique(arr) {
return arr.filter(function(elem, pos) {
return arr.indexOf(elem) == pos;
});
}
function sym(args) {
var arg = [].slice.call(arguments);
return arg.map(unique).reduce(function(previous, current) {
return complement(previous, current).concat(complement(current, previous)); });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment