const A = [
[4,5,10],
[1,20,3],
[0,5,-6],
[1,200,3],
];
MAX des colonnes : 4,200,10
Avant Map/reduce
function maxi(A){
let maxC = [];
for( let c=0; c < A[0].length; c++){
let max = -Infinity;
for ( let l=0; l < A.length; l++){
if ( max < A[l][c] ) max = A[l][c];
}
maxC.push(max);
}
return maxC;
}
Après Map/reduce
let AMax = A[0].map( function (_,col) {
return A.reduce( function (acc,lig) {
return Math.max(acc,lig[col])
} ,-Infinity)
});