Guest User

Untitled

a guest
May 25th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. //metodos Array filter()
  12.  
  13. let almuerzos = [
  14. {principal: 'arepa', postre:'helado'},
  15. {principal: 'tacos', postre:'torta de queso'},
  16. {principal: 'pizza', postre:'galletas'},
  17. {principal: 'sushi', postre:'quesillo'},
  18. {principal: 'arepa', postre:'golfeados'},
  19. {principal: 'arepa', postre:'churros'},
  20. ];
  21.  
  22. /*
  23. let postresParaPlatosConArepas = [];
  24.  
  25. for (let i = 0; i < almuerzos.length; i++) {
  26.  
  27. if(almuerzos[i].principal === 'arepa')
  28. postresParaPlatosConArepas.push(almuerzos[i].postre)
  29. }
  30.  
  31. console.log(postresParaPlatosConArepas);
  32. */
  33.  
  34. let postresParaPlatosConArepas = almuerzos
  35. .filter((almuerzo) => {
  36. return almuerzo.principal === 'arepa';
  37. })
  38. .map( (almuerzo) => almuerzo.postre)
  39.  
  40. console.log(postresParaPlatosConArepas);
  41. </script>
  42.  
  43.  
  44.  
  45. <script id="jsbin-source-javascript" type="text/javascript">//metodos Array filter()
  46.  
  47. let almuerzos = [
  48. {principal: 'arepa', postre:'helado'},
  49. {principal: 'tacos', postre:'torta de queso'},
  50. {principal: 'pizza', postre:'galletas'},
  51. {principal: 'sushi', postre:'quesillo'},
  52. {principal: 'arepa', postre:'golfeados'},
  53. {principal: 'arepa', postre:'churros'},
  54. ];
  55.  
  56. /*
  57. let postresParaPlatosConArepas = [];
  58.  
  59. for (let i = 0; i < almuerzos.length; i++) {
  60.  
  61. if(almuerzos[i].principal === 'arepa')
  62. postresParaPlatosConArepas.push(almuerzos[i].postre)
  63. }
  64.  
  65. console.log(postresParaPlatosConArepas);
  66. */
  67.  
  68. let postresParaPlatosConArepas = almuerzos
  69. .filter((almuerzo) => {
  70. return almuerzo.principal === 'arepa';
  71. })
  72. .map( (almuerzo) => almuerzo.postre)
  73.  
  74. console.log(postresParaPlatosConArepas);
  75.  
  76.  
  77.  
  78.  
  79.  
  80. </script></body>
  81. </html>
Add Comment
Please, Sign In to add comment