Skip to content

Instantly share code, notes, and snippets.

Created December 9, 2015 08:03
Show Gist options
  • Save anonymous/c4d9471198ad5ccae736 to your computer and use it in GitHub Desktop.
Save anonymous/c4d9471198ad5ccae736 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/patrickcurl 's solution for Bonfire: Diff Two Arrays
// Bonfire: Diff Two Arrays
// Author: @patrickcurl
// Challenge: http://www.freecodecamp.com/challenges/bonfire-diff-two-arrays
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function diff(arr1, arr2) {
var newArr = [];
arr1.forEach(function(a){
if(arr2.indexOf(a) == -1){
newArr.push(a);
}
});
arr2.forEach(function(a){
if(arr1.indexOf(a) == -1){
newArr.push(a);
}
});
return newArr.sort();
}
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