Last active
September 24, 2020 12:13
-
-
Save ekrem-aktas/41427c85441c803e1a53d60d844e30b5 to your computer and use it in GitHub Desktop.
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
const basket = [ | |
{ name:"apple", type: "fruit" }, | |
{ name:"broccoli", type: "vegetable" } | |
]; | |
// Array.reduce can be used to filter fruits | |
const fruits = basket.reduce((acc, food) => food.type === "fruit" ? acc.concat(food) : acc, []); | |
// But Array.filter is better for it | |
const fruits = basket.filter(food => food.type === "fruit"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment