-
-
Save simeg/9188e7c58b35f766431d3e77f1cdb485 to your computer and use it in GitHub Desktop.
FP in JS 4
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
// A list of fruit, and their price | |
const fruit = [ | |
{name: 'banana', price: 5}, | |
{name: 'apple', price: 3}, | |
{name: 'pear', price: 7} | |
]; | |
// We use filter() to say | |
// "only include fruit that has a price of 5 or less" | |
const cheapFruit = fruit | |
.filter(f => f.price <= 5); | |
// Log the result to see that "pear" was filtered out | |
console.log(cheapFruit); // [ {name: 'banana', price: 5}, {name: 'apple', price: 3} ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment