Skip to content

Instantly share code, notes, and snippets.

@chriswrightdesign
Last active June 23, 2017 03:42
Show Gist options
  • Save chriswrightdesign/1c240887391206c3dabc23d5d5b3d986 to your computer and use it in GitHub Desktop.
Save chriswrightdesign/1c240887391206c3dabc23d5d5b3d986 to your computer and use it in GitHub Desktop.
Function five ways
const valueEquals = value => comparison => value === comparison;
const people = ['bob', 'sarah', 'kate', 'john', 'steve', 'stu', 'sam'];
people.filter(valueEquals('sarah'));
// returns an array value where any value equals sarah
people.find(valueEquals('bob'));
// returns the first value it finds ‘bob’
people.every(valueEquals('john'));
//returns false, since not every value equals ‘john’
people.some(valueEquals('steve'));
// returns true, since there’s a single value called steve
people.findIndex(valueEquals('kate'));
// returns 2, the index of kate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment