JSFiddle - React, Tailwind, and code Playground
JavaScript
var xnombre = [1,2,3,4,5,24,44,124,125,165];
var xacomp = [1,5,44,55,124];
function sortNumber(a,b) {
return a - b;
}
xnombre.sort(sortNumber);
xacomp.sort(sortNumber);
function intersection_destructive(a, b)
{
var result = new Array();
while( a.length > 0 && b.length > 0 )
{
if (a[0] < b[0] ){ a.shift(); }
else if (a[0] > b[0] ){ b.shift(); }
else /* they're equal */
{
result.push(a.shift());
b.shift();
}
}
return result;
}
alert(intersection_destructive(xnombre, xacomp));