Use the higher-order function to provide a new control flow:
Let's look into an example that uses the higher-order function to provide a new control flow:
xxxxxxxxxx
13
const intArr = [3,10,25,2,7]
function customForEach(arr,fn){
for(let i=0; i<arr.length; i++){
fn(arr[i] % 2 == 0, () => {
console.log(arr[i], "is even");
});
}
}
function unless(test, then) {
if (test) then();
}
customForEach(intArr,unless);
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment