I have been seeing this term mentioned in several blogs, but I have no clear idea what they are. Can someone please help me understand the concept of higher order functions?
sort(), map() and reduce() are all examples of higher order functions. They all take a function or lambda as a parameter
const a = [3,7,1,2,4,8];
const b = a.sort((f, n) => f < n);
console.log(b);
> [ 8, 7, 4, 3, 2, 1 ]
This video will explain you it very well Higher-order functions - Part 1 of Functional Programming in JavaScript
I have difficulties describing it, but here's an example from what I know (and might be totally wrong):
function greet(name, salutation) { return 'Hello ' + salutation + ' ' + name }
greet('Foo', 'Mr') // => 'Hello Mr Foo'
// higher order function
function greetMr (name) { return greet(name, 'Mr') }
greetMr('Foo') // => 'Hello Mr Foo'
Here greetMr is an example of a higher order function, CMIIW
j
stuff ;)
I quote wikipedia:
those would be higher order function. :)