Pages

Affichage des articles dont le libellé est map. Afficher tous les articles
Affichage des articles dont le libellé est map. Afficher tous les articles

Map en action


  1. function alphabetRange (start, end, step = 1) {
  2.   return new Array(Math.ceil((end.charCodeAt(0) - start.charCodeAt(0))/step))
  3.   .fill(start.charCodeAt(0))
  4.   .map((x, i) => String.fromCharCode(i*step + start.charCodeAt(0)));
  5. }

  6. console.log(alphabetRange('c', 'h', 2));

Map en action

let p = '<h1>escapeForHTML<h1>';



let regex = /[<>&]/gi;



let r = new Map([
  ['>','&gt;'],

  ['&','&amp;'],

  ['<', '&lt;'],

]);


let f = c => r.get(c)


document.body.insertAdjacentHTML("afterbegin",p);

document.body.insertAdjacentHTML("afterbegin",p.replace(regex,f));

transformer le code

const B=[
  [1,2,3],
  [4,5,6],
];

// c = col, l = lig
function maxi(A){
      let maxC = [];
      for( let c=0; c < A[0].length; c++){ // A[0]=indique la dim
          let tmp = [];
          let max = -10000; //  
          for ( let l=0; l < A.length; l++){
                 tmp.push(A[l][c]); 
                 if ( max < A[l][c] ) max = A[l][c];
          }
          console.log(tmp);
          //console.log(Math.max(...tmp)); //top version
          console.log(max);
          maxC.push(max);
      }
      console.log(maxC);
      return maxC;

}

console.log(`les valeurs Max par colonnes : ${maxi(B)}`);

Remplacer ce code avec reduce et map