Skip to content

Instantly share code, notes, and snippets.

@dillansimmons
Last active October 18, 2016 18:08
Show Gist options
  • Save dillansimmons/7b33cede0803cb2f85f6a4e677392323 to your computer and use it in GitHub Desktop.
Save dillansimmons/7b33cede0803cb2f85f6a4e677392323 to your computer and use it in GitHub Desktop.
Map and find duplicates in 2 arrays
// 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