Skip to content

Instantly share code, notes, and snippets.

@simeg

simeg/fp_js_4.js Secret

Created May 23, 2022 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simeg/9188e7c58b35f766431d3e77f1cdb485 to your computer and use it in GitHub Desktop.
Save simeg/9188e7c58b35f766431d3e77f1cdb485 to your computer and use it in GitHub Desktop.
FP in JS 4
// 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