Guest User

Untitled

a guest
Apr 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. <script>
  2. const companies = [
  3. {name: "Company One", category: "Finance", start: 1981, end: 2012},
  4. {name: "Company Two", category: "Retail", start: 1992, end: 2016},
  5. {name: "Company Three", category: "Auto", start: 1999, end: 2013},
  6. {name: "Company Four", category: "Technology", start: 1989, end: 2008},
  7. {name: "Company Five", category: "Finance", start: 2007, end: 2001},
  8. {name: "Company Six", category: "Auto", start: 1997, end: 2005},
  9. {name: "Company Seven", category: "Technology", start: 1987, end: 2003},
  10. {name: "Company Eight", category: "Retail", start: 1989, end: 2009},
  11. {name: "Company Nine", category: "Food", start: 1911, end: 2010}
  12. ]
  13.  
  14. const ages = [33, 25, 12, 20, 17, 34, 56, 87, 63, 8, 73];
  15.  
  16. // map()
  17. const testMap = companies.map(function(company) {
  18. return company.name;
  19. });
  20.  
  21. // map() using fat arrows
  22. const ageMap1 = ages.map((age) => { return Math.sqrt(age) });
  23. const ageMap2 = ages.map((age) => Math.sqrt(age));
  24.  
  25. console.log(testMap);
  26. console.log(ageMap1);
  27. console.log(ageMap2);
  28.  
  29. // testMap
  30. ["Company One", "Company Two", "Company Three", "Company Four", "Company Five", "Company Six", "Company Seven", "Company Eight", "Company Nine"]
  31.  
  32. // ageMap1
  33. [5.744562646538029, 5, 3.4641016151377544, 4.47213595499958, 4.123105625617661, 5.830951894845301, 7.483314773547883, 9.327379053088816, 7.937253933193772, 2.8284271247461903, 8.54400374531753]
  34.  
  35. // ageMap2
  36. [5.744562646538029, 5, 3.4641016151377544, 4.47213595499958, 4.123105625617661, 5.830951894845301, 7.483314773547883, 9.327379053088816, 7.937253933193772, 2.8284271247461903, 8.54400374531753]
  37.  
  38. </script>
Add Comment
Please, Sign In to add comment