We are creating a calculator that can do three types of calculation:
- doubling a number with the
double
function - halving a number with the
halve
function - squaring a number with the
square
function
Complete the functions so that calculate
takes one of the functions that implement an operation and a number as arguments, and returns the result of the calculation.
function double(x) {
// write solution here
}
function halve(x) {
// write solution here
}
function square(x) {
// write solution here
}
function calculate(/* write parameters here */) {
// write solution here
}
// Examples
console.log(calculate(double, 4)); // 8
console.log(calculate(halve, 4)); // 2
console.log(calculate(square, 4)); // 16