Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var years = [1990, 1965, 1937, 2005, 1998];
  2.  
  3. function arrayCalc(arr, fn) {
  4.     var arrRes = [];
  5.     for (var i = 0; i < arr.length; i++) {
  6.         arrRes.push(fn(arr[i]));
  7.     }
  8.     return arrRes;
  9. }
  10.  
  11. function calculateAge(el) {
  12.     return 2020 - el;
  13. }
  14.  
  15. function isFullAge(el) {
  16.     return el >= 18;
  17. }
  18.  
  19. var ages = arrayCalc(years, calculateAge);
  20. var fullAges = arrayCalc(ages, isFullAge);
  21.  
  22. console.log(ages);
  23. console.log(fullAges);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement