Created
November 20, 2015 06:15
-
-
Save minsooshin/79feac5c0e01dc393acb to your computer and use it in GitHub Desktop.
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: @minsooshin | |
// 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 = []; | |
function check(a1, a2) { | |
var obj = {}; | |
a1.map(function(val) { | |
obj[val] = true; | |
}); | |
a2.map(function(val) { | |
if (!obj[val]) newArr.push(val); | |
}); | |
} | |
check(arr1, arr2); | |
check(arr2, arr1); | |
// Same, same; but different. | |
return newArr; | |
} | |
diff(["andesite", "grass", "dirt", "pink wool", "dead shrub"], ["diorite", "andesite", "grass", "dirt", "dead shrub"]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment