Skip to content

Instantly share code, notes, and snippets.

@luislobo14rap
Last active August 23, 2018 01:12
Show Gist options
  • Save luislobo14rap/583a3b8407f5e4406eb8fa9129b676b0 to your computer and use it in GitHub Desktop.
Save luislobo14rap/583a3b8407f5e4406eb8fa9129b676b0 to your computer and use it in GitHub Desktop.
// arrayIntersection.js v1
function arrayIntersection(arrayA, arrayB) {
let newArray = [];
for (let i = 0; i < arrayA.length; i++) {
if (arrayB.indexOf(arrayA[i]) > -1) {
newArray.push(arrayA[i]);
};
};
return newArray;
};
Array.prototype.intersection = function(arrayB) {
return arrayIntersection(this, arrayB);
};
// arrayIntersection.min.js v1
function arrayIntersection(a,b){let c=[];for(let d=0;d<a.length;d++)-1<b.indexOf(a[d])&&c.push(a[d]);return c}Array.prototype.intersection=function(a){return arrayIntersection(this,a)};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment