Order Up!

Can I get an array containing:
Only the apples?
[, , , , ]

Ingredients

Loading editor...

[
  "apple",
  "banana",
  "apple",
  "apple",
  "banana"
]

Code Kitchen

function cook(ingredients) {

Loading editor...

return ingredients.filter(item => ...your code here...);
}

Filter: Intro

The filter() method will return a new array with only the elements that pass the callback function.

The callback function takes in each element and returns true if you want to keep it, otherwise false.

Ex: arr.filter(x => x == 5)

This example will return a new array with only the elements that are equal to 5.