Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function mapfilter(array, pred){
  2.  let acc = [];
  3.  for(let e of array){
  4.    let a = pred(e);
  5.    if(a !== null) acc.push(a);
  6.  }
  7.  return acc;
  8. }
  9.  
  10. const tags = [
  11.   { name: "Linux", score: .6 },
  12.   { name: "Open Source", score: .7 },
  13.   { name: "Bash", score: .9 },
  14.   { name: "Shell", score: .8 },
  15.   { name: "Awk", score: .2 },
  16.   { name: "Sed", score: .3 },
  17. ];
  18.  
  19. let nameOfTagIfHighScore = (tag) => tag.score > 0.5 ? tag.name : null;
  20. let result = mapfilter(tags,nameOfTagIfHighScore);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement