Tuesday, September 14, 2021

Example of function taking function as arguments.

 var year=[1990,1965,1970,1980];

function arrayCalc(arr,fn){

    var res=[];

    for(var i=0;i<arr.length;i++){

        res.push(fn(arr[i]))

    }

    return res;

}

function calculateAge(el){

    return 2021-el;

}

var result=arrayCalc(year,calculateAge);//here calculateAge is the callback function .

console.log(result);


No comments:

Post a Comment

Testing controller

------Controller------------- @RestController @RequestMapping("/items") public class ItemController {     private final ItemServic...