DEV Community

Discussion on: Javascript array iteration with 'some()' and 'every()'

Collapse
 
joelnet profile image
JavaScript Joel

Great article!

With curry and partial application, you can also use some like this:

const contacts = ['Stewie', 'Meg', 'Quagmire', 'Cleveland'];

const equals = a => b => a === b

contacts.some(equals('Lois')) // false
contacts.some(equals('Meg')) // true

You could also write every like this:

const propGte = prop => val => obj => obj[prop] >= val;
const lengthGte = propGte('length');

['Stewie', 'Meg', 'Quagmire', 'Cleveland'].every(lengthGte(4)); // false
['Stewie', 'Megan', 'Quagmire', 'Cleveland'].every(lengthGte(4)); // true