Last active
October 18, 2016 18:08
-
-
Save dillansimmons/7b33cede0803cb2f85f6a4e677392323 to your computer and use it in GitHub Desktop.
Map and find duplicates in 2 arrays
This file contains 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
// Arrays | |
var x = ["7","?","X","X","Q", "?"]; | |
var y = ["?","X","Z","Q", "?", "?"]; | |
var find_dupes = function (array1, array2) { | |
/* Map Arrays, make uppercase if neccessary | |
var xx = array1.map(function(x){ return x.toUpperCase() }) | |
var yy = array2.map(function(x){ return x.toUpperCase() }) */ | |
// Sort xx against yy | |
var map = array1.filter(function(val) { | |
return array2.indexOf(val) != -1; | |
}); | |
// return duplicates between arrays | |
return JSON.stringify(map); | |
} | |
// Print Function | |
console.log(find_dupes(x,y)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment