Functions of higher order that abstract over actions:
In addition to implementing abstraction on values, higher-order functions can also implement abstraction on actions. The following code uses examples to illustrate how it can implement abstraction over actions.
xxxxxxxxxx
13
const intArr = [3,10,25,1,7]
function filterArr(arr) {
const newArray = [];
return function greaterThan(m){
for(let i=0; i<arr.length; i++){
if(arr[i] > m){
newArray.push(arr[i]);
}
}
console.log("Elements that are greater than m = "+ m + " are: "+ newArray);
}
}
filterArr(intArr)(9);
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment