Array Intersection
without Set.intersection()
by Jake
JavaScript
function array_intersection ( ...args ) {
if ( args.length < 2 )
return args[0];
var out = [];
args.forEach( arr => out = [ ...out, ...arr ] );
// all will have dupes, shouldn't matter
for( let i=0; i < args.length; i++ ) {
out = out.filter( value => args[i].includes(value) )
}
// now unique it
return Array.from( new Set( out ) );
}
var x = [
[ 1, 2, 3, 4, 5 ],
[ 3, 4, 5, 6, 7 ],
[ 4, 5, 6, 7, 8 ]
];
var y = array_intersection( ...x );
console.log( 'y', y );