- function alphabetRange (start, end, step = 1) {
- return new Array(Math.ceil((end.charCodeAt(0) - start.charCodeAt(0))/step))
- .fill(start.charCodeAt(0))
- .map((x, i) => String.fromCharCode(i*step + start.charCodeAt(0)));
- }
- console.log(alphabetRange('c', 'h', 2));
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
Map en action
let p = '<h1>escapeForHTML<h1>';
let regex = /[<>&]/gi;
let r = new Map([
['>','>'],
['&','&'],
['<', '<'],
]);
let f = c => r.get(c)
document.body.insertAdjacentHTML("afterbegin",p);
document.body.insertAdjacentHTML("afterbegin",p.replace(regex,f));
let regex = /[<>&]/gi;
let r = new Map([
['>','>'],
['&','&'],
['<', '<'],
]);
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
[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
Inscription à :
Articles (Atom)