Anthony Boyac Anthony Boyac - 1 year ago 59
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?

Answer Source

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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download