Can someone please help me with higher order functions?


Hello guys, can you please help me with this

In instruction 1:

Why is that correct instead of doing:

const time2p2 = timeFuncRuntime =>


In instruction 2:

Why is it calling the arguments “func(val)” and not “(func,val)”?

Thanks in advance


Notice the structure of your function expression already has the variables func and val when you write

const checkConsistentOutputput = (func, val) => {/*some code*/};

What that means is that the func variable is already being considered as a function (if it’s all written correctly). So all you have to do is invoke that function func(whateverInput);.

In simpler terms, checkConsistentOutput() is a function that takes another function and a value and checks for consistent behavior from that other function.


But why is “func” being considered a function and val an input?

Did they teach us how to do that synthaxis?

It is simply a matter of how you pass in the arguments. Functions are objects, just like strings, integers, etc. So, you can just as easily pass in a function argument or a string argument. But in the code, you have to treat each argument correctly:

function someFunc(func, val){
  return func(val);
someFunc(3, "hello");

This would throw an error since you cannot call "hello" on a number.
I hope this helps!

1 Like