Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // an array of random years
- var years = [1990, 1965, 1937, 1998, 1988];
- // function to place all given values into a new array in this case arrRes
- function arrayCalc(arr, fn){
- var arrRes = [];
- for (var i = 0; i < arr.length; i++) {
- arrRes.push(fn(arr[i]));
- }
- return arrRes;
- }
- //function to calculate the age
- function calcage(el){
- return 2019 - el;
- }
- var ages = arrayCalc(years, calcage);
- console.log(ages);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement