Created
May 8, 2017 18:46
-
-
Save MicFin/b5f22f8adf9ab788c5bf61e23c9f70e9 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' | |
// Example array | |
const numsArray = [0, 1, 2, 3, 4] | |
// Filter for odd elements in an array using predicate function | |
const isOdd = (num) => { | |
return num % 2 | |
} | |
odds = numsArray.filter(isOdd) | |
// Filter for odd elements in an array using anonymous arrow function | |
const odds = numsArray.filter(num => { return num % 2 }) | |
// Filter for only countries that launched 20+ rockets | |
// using a predicate function | |
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 isAggressive = rocket => { return rocket.launches >= 20 } | |
const aggressiveCountries = rockets.filter(isAggressive) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment