Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TylerL-uxai/f5de946a6704d294bcc4 to your computer and use it in GitHub Desktop.
Save TylerL-uxai/f5de946a6704d294bcc4 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/tylerl-uxai 's solution for Bonfire: Diff Two Arrays
// Bonfire: Diff Two Arrays
// Author: @tylerl-uxai
// Challenge: http://www.freecodecamp.com/challenges/bonfire-diff-two-arrays
// Learn to Code at Free Code Camp (www.freecodecamp.com)
// with the help of http://wulkan.me/bonfire-diff-two-arrays/ and https://github.com/pfilippi24
function diff(arr1, arr2) {
// Same, same; but different.
return arr1.concat(arr2).filter(function(val){
return !(arr1.indexOf(val)>=0 && arr2.indexOf(val) >=0);
});
}
diff([1, 2, 3, 5], [1, 2, 3, 4, 5]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment