Write Higher Order Arrow Functions need help

Tell us what’s happening:
I’m really stuck here, can someone explain to me the utility and how to use filter (), map () or reduce ()?

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) coc_coc_browser/77.0.126 Chrome/71.0.3578.126 Safari/537.36.

Link to the challenge:

It would be easier for you to follow a video about this topic: JavaScript Higher Order Functions & Arrays
Make sure you write the code alongside the video instructor. It should help you a ton! :slight_smile:

1 Like

That’s exactly what I need, thank you

1 Like

still wonder how the Animal, Index and Animals works in the map function I use below, can you explain it to me?

// This is my code

const animals = [
“name”: “cat”,
“size”: “small”,
“weight”: 5
“name”: “dog”,
“size”: “small”,
“weight”: 10
“name”: “lion”,
“size”: “medium”,
“weight”: 150
“name”: “elephant”,
“size”: “big”,
“weight”: 5000

let animal_names = animals.map((animal, index, animals) => {
return animal.name

Basically it will loop through your animals array and inside the arrow function, you can use the variable animal to acces that member like:

animal.name; animal.size; animal.weight;

=> These will return those properties.
index is just the index at which the array is currently at. (eg. 0, 1, 2, etc); And animals is the array itself if, for some reason you want to access them inside the function (but most of the times you won’t need to do that).

In your case, animal_name will now contain all the names from the animals in an array. You should test your code and see how it works.

1 Like