Created
May 8, 2017 18:48
-
-
Save MicFin/6417ae43e20abd587d0924349a37385f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
'use strict' | |
// Starting array | |
const ages = [7, 24, 21, 18, 22] | |
// Use indexOf to find the position of 21 | |
ages.indexOf(21) // 2 | |
// Use findIndex to find the position of first age over 21 | |
// using a predicate function | |
const isAdult = (age) => { | |
return age >= 21 | |
} | |
ages.findIndex(isAdult) // 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment