Anthony Boyac Anthony Boyac - 5 months ago 26
Javascript Question

write a twice function that multiplies one number four times by itself in the format below

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

. For example,

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

should return
. How do I do it?


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