Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. // an array of random years
  2. var years = [1990, 1965, 1937, 1998, 1988];
  3.  
  4. // function to place all given values into a new array in this case arrRes
  5. function arrayCalc(arr, fn){
  6. var arrRes = [];
  7. for (var i = 0; i < arr.length; i++) {
  8. arrRes.push(fn(arr[i]));
  9. }
  10. return arrRes;
  11. }
  12.  
  13.  
  14. //function to calculate the age
  15. function calcage(el){
  16. return 2019 - el;
  17. }
  18.  
  19.  
  20. var ages = arrayCalc(years, calcage);
  21. console.log(ages);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement