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

filter : thisarg

 

  1. function majeur( {born, sex} ) {

  2.   return (born < this.born  && sex == this.sex) }


  3. let f = {

  4.   sex : "f",

  5.   born : 2002,

  6. }


  7. let h = {

  8.   sex : "h",

  9.   born : 2000,

  10. }


  11. let hommesMajeur = tabPers.filter(majeur,h),

  12.      femmesMajeur = tabPers.filter(majeur,f);




code


Filtre


  1. const filter = 

  2.   (fx, array) => array.reduce(

  3.     (acc, item) => fx(item) ? acc.concat(item) : acc, 

  4.   []);

  5. const greaterThan4 = (x) => x >= 4;

  6. const data   = [0, 1, 2, 3, 4, 5];

  7. let result = filter(greaterThan4, data);


code