Instructor: A higher order function is any function that does at least one of the following two things, and oftentimes does both. First, it accepts a function as an argument. Second, it might return a new function.
To demonstrate this, we're going to create a width, count higher-order function. With count, we'll take a function as an argument. What it will do is return a console log of how many times we've called our newly return function from within it.
To do this, we'll store a count variable. We'll return a new function that uses the rest operator to gather up the arguments passed to it. Inside the body of our return function, we'll log out the count while also incrementing it. We'll return the results of the function that's been called with the spread arguments.
Now that we have our width, count higher-order function, let's create a simple add function to use and pass into it. It will receive X and Y as arguments and return their summation. We can now create a counted add function by using our width, count function and passing add to it.
Now, let's log out several uses of counted add. I'll modify some of the arguments. If we save this and print it out in the terminal, we should see a call count with each one.