Last active
June 23, 2017 03:42
-
-
Save chriswrightdesign/1c240887391206c3dabc23d5d5b3d986 to your computer and use it in GitHub Desktop.
Function five ways
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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