DEV Community

loading...

Discussion on: JavaScript Array.some() or Array.every()?

Collapse
aminnairi profile image
Amin

Very nice explanations, Rakhi, thanks!

You could even use some higher-order functions to create a slick little API for checks that we often use on arrays.

"use strict";

const is = searchedItem => item => item === searchedItem;
const hasLengthGreaterThan = length => item => item.length > length;

const fruits = ["banana", "pear", "apple", "strawberry"];

const hasStrawberry = fruits.some(is("strawberry")); // true
const hasLongName = fruits.some(hasLengthGreaterThan(15)); // false
Enter fullscreen mode Exit fullscreen mode
Collapse
arvindsridharan profile image
arvindsridharan

It would be great if you could cover higher order functions in detail.

Collapse
aminnairi profile image