DEV Community

Discussion on: What is a Higher-Order Function?

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️ • Edited

If you're targetting only modern browsers, you can also write the validate function much more easily:

validate = (subject, ...tests) => tests
   .map((test)=>test(subject))
   .reduce((a,b)=>a&&b);

or the validator function as

validator = (...tests) => (subject) => tests
   .map((test)=>test(subject))
   .reduce((a,b)=>a&&b);