Created
December 9, 2015 08:03
-
-
Save anonymous/c4d9471198ad5ccae736 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/patrickcurl 's solution for Bonfire: Diff Two Arrays
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: 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