Anthony Boyac - 6 months ago 29

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);
```