Pages

td

let pers =  [
{nom: "Dupont",ville: "evry",sex: "f"},
{nom: "Brusel",ville: "belfort",sex: "h"}
];

console.log(pers);

for ( let v of pers){
  if ( v.sex == "h" )
    console.log(`Monsieur ${v.nom}`);
  else
    console.log(`Madame ${v.nom}`);
}

for ( let v of pers){
  if ( v.sex == "h" )
    console.log(`Cher ${v.nom}`);
  else
    console.log(`Chere ${v.nom}`);
}

for ( let v of pers){
    console.log(`${v.nom} habite à ${v.ville}`);
}

function affiche_0(tab, callback) {
    for (let ele of tab){
         console.log(callback(ele))
    }
}

function civilite_0(pers){
  return (pers.sex =='h' ? `Monsieur ${pers.nom}` : `Madame ${pers.nom}`);
}

affiche_0(pers,civilite_0);

function civilite({nom,sex}) {
   return (sex=='h' ? `Monsieur ${nom}` : `Madame ${nom}`);
}

function affiche(tab, callback) {

for (let ele of tab){
console.log(callback ? callback(ele) : `${ele.nom} habite à ${ele.ville}`);


};

affiche(pers,civilite);