Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MinSomai/5fc088b5974e6822c3f6e1dffaa2efda to your computer and use it in GitHub Desktop.
Save MinSomai/5fc088b5974e6822c3f6e1dffaa2efda to your computer and use it in GitHub Desktop.
Intermediate Algorithm Scripting: Diff Two Arrays
function diffArray(arr1, arr2) {
let first = checkOnce(arr1, arr2);
let second = checkOnce(arr2, arr1);
return first.concat(second);
}
function checkOnce(arr1, arr2){
let unique = [];
arr1.every(item=>{
if(!arr2.some(innerItem=> {
if(innerItem == item)
return true;
else
return false;
})){
unique.push(item);
}
return true;
});
return unique;
}
diffArray(["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