DEV Community

Discussion on: Functional Programming in JavaScript

Collapse
 
mrdreix profile image
Vladimír Gál

Instead of looping we could use find too right ? We really don't like to use for/while etc unless we have to

const anyMatch = (list,predicate) => {
    return list.find(item => predicate(item)) != null
}
Collapse
 
hunter profile image
Hunter Henrichsen • Edited

We could, but for someone who is not familiar with functional programming it's a little strange. We could also do this:

const anyMatch = (list, predicate) => list.some(predicate);

The point is to illustrate how this would work without applying functional programming to everything in order to build some understanding using familiar constructs.