Skip to content

Instantly share code, notes, and snippets.

@shanebarringer
Last active August 5, 2016 18:01
Show Gist options
  • Save shanebarringer/9946623a24b0400b9cdfe007b7b05cf4 to your computer and use it in GitHub Desktop.
Save shanebarringer/9946623a24b0400b9cdfe007b7b05cf4 to your computer and use it in GitHub Desktop.
let numbers = [1,2,3,4,5,6,7,8,9];
let otherNumbers = [18, 36, 4, 2, 19, 8, 7, 16, 45];
Array.prototype.compare = (firstArray, secondArray) => {
let uniqueNumbers = [];
firstArray.forEach((number) => {
let comparison = secondArray.some((otherNumber) => {
return number === otherNumber;
});
!comparison ? uniqueNumbers.push(number) : null;
});
return uniqueNumbers;
};
let foo = [].compare(numbers, otherNumbers);
console.log(foo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment