Anthony Boyac - 8 months ago 35

Javascript Question

I want to write a function called twice that takes a function f and a value x as its parameters and returns

`f(f(x))`

`twice(function (x) { return x * x; }, 3)`

should return

`81`

Answer

What is stopping you? You already has the answer with you. It is working pretty fine.

```
function twice(f, x) {
return f(f(x));
}
var result = twice(function(n){return n*n;}, 3);
console.log(result);
```

Source (Stackoverflow)