Skip to content

Instantly share code, notes, and snippets.

@MicFin
Created May 8, 2017 18:49
Show Gist options
  • Save MicFin/23b2c09ec919ed12bdf7bd2118aeb911 to your computer and use it in GitHub Desktop.
Save MicFin/23b2c09ec919ed12bdf7bd2118aeb911 to your computer and use it in GitHub Desktop.
'use strict'
// Starting array
const ages = [7, 24, 21, 18, 22]
// Use find to return the age of first age over 21
// using a predicate function
const isAdult = (age) => {
return age >= 21
}
ages.find(isAdult) // 24
// Find the first country that launched 20 or less rockets
// using a predicate function called isCalm
const rockets = [
{ country: 'Russia', launches: 32 },
{ country: 'US', launches: 23 },
{ country: 'China', launches: 16 },
{ country: 'Europe(ESA)', launches: 7 },
{ country: 'India', launches: 4 },
{ country: 'Japan', launches: 3 }
]
const isCalm = rocket => {
return rocket.launches <= 20
}
rockets.find(isCalm) // { country: 'China', launches: 16 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment