javascript
Higher order Function part - 1
const radius = [3, 1, 2, 4];
const area = function (radius) { return Math. PI* radius* radius; };
const cicumference = function (radius) {
return 2 * Math.PI * radius;
};
const diameter = function (radius) { return 2 * radius;
};
const calculate = function (radius, logic) {
const output = [];
for (let i = 0; i < radius.length; i++) { output.push(logic(radius[i]));
}
return output;
};
console.log(calculate(radius, area));
console.log(calculate(radius, cicumference)); console.log(calculate (radius, diameter));
Was this helpful?
Similar Posts
- Higher order Function
- Pass a function as parameter of another function in Javascript
- Order and find elements
- Run a function every 5 seconds interval using Javascript
- Run a Javascript function after user finished writing in the input field
- Pass multiple arguments when calling a function which takes single argument Javascript
- Assign default values to function parameters in Javascript