In most languages, functions can be passed around just like numbers or strings. That's the foundation of everything from callbacks to React hooks.
Write a function applyTwice that takes:
f that takes one integer and returns one integernβ¦and returns the result of applying f to n twice.
applyTwice(x => x + 3, 7) β 13 // (7+3)+3
applyTwice(x => x * 2, 5) β 20 // (5*2)*2
Your program receives two command-line arguments:
add:<k> or mul:<k>Print the result.
applyTwice must accept a function as its first argument β do not hardcode the operation inside it.add:<k> and mul:<k>.