<script>
var arrF = [3, 5, 8];
var arrS = [1, 2, 3, 5, 8];
function getIntersect(arr1, arr2) {
if (arr1.length < arr2.length) {
[arr1, arr2] = [arr2, arr1];
}
for (var i = 0; i < arr1.length; i++) {
for (var j = 0; j < arr2.length; j++) {
if (arr1[i] === arr2[j]) {
arr1[i] = arr2[j] = 0;
}
}
}
return [arr1, arr2];
}
alert(JSON.stringify(getIntersect(arrF, arrS)));
</script>
вариант