re: The Power of Higher Order Functions in JavaScript (With examples and use cases) VIEW POST

re: i also suggest a re write to this functionality of the last pass filterMaleFrogs = function (frog) { return frog.gender === 'Male' }; filter...

Hi SerjoA, thank you for the suggestion and the workaround!

I will edit the post and swap out the current code example with the example you provided because its correct.

I'm going to make a slight modification to your combineFilters function to run this instead:

function combineFilters(...fns) {
   return function (frog) {
     for (let i = 0; i < fns.length; i++) {
       const filter = fns[i]
       const passes = filter(frog)
       if (passes) {
       } else {
         return false
     return true

This is a slightly more optimized version which reduces the amount of iterations as much as possible.

Thank you!

code of conduct - report abuse