404flanker,
<script>
var a = [5,7,1,2,7],
b = [2,8,1,1,5],
aMin = Math.min.apply(null,a),
aMax = Math.max.apply(null,a),
bMin = Math.min.apply(null,b),
bMax = Math.max.apply(null,b);
a.forEach(function(item, i, arr) {
if(item == aMin) arr[i] = bMin;
if(item == aMax) arr[i] = bMax;
});
b.forEach(function(item, i, arr) {
if(item == bMin) arr[i] = aMin;
if(item == bMax) arr[i] = aMax;
});
document.write(a+ "<br>" + b)
</script>
https://learn.javascript.ru/array-iteration
https://learn.javascript.ru/call-apply#метод-apply