Functional Programming - Use the filter Method to Extract Data from an Array

Hi, everyone! I’ m Weber, and I just started learning the basics of JavaScript recently.

Somehow this challenge is quite hard for me. Please help me!!! :cry:

My failed code is:

const filteredList = watchList.map ( x => ({
title: x[“Title”],
rating: x[“imdbRating”].filter(y => y >= 8.0)
})
)

It keeps showing “TypeError: x.imdbRating.filter is not a function” here.

I can’t figure out how to sort it out.

Any correction and help would be greatly appreciated!!!

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36

Challenge: Functional Programming - Use the filter Method to Extract Data from an Array

Link to the challenge:

You have two issues here

No.1:
You have applying filter in the wrong place

You map method technically ends here

const filteredList = watchList.map(x => ({
   title: x["Title"],
   rating: x["imdbRating"]
 })

You should chain the filter method at the end there

No.2:
You should console.log what y is

 const filteredList = watchList.map(x => ({
   title: x["Title"],
   rating: x["imdbRating"]
 })).filter(y => console.log(y))

Then you will need to modify your code, so that it correctly filters out ratings that are greater then or equal to 8.0

If you need extra help, you should look at the example they gave you here

const users = [
  { name: 'John', age: 34 },
  { name: 'Amy', age: 20 },
  { name: 'camperCat', age: 10 }
];

const usersUnder30 = users.filter(user => user.age < 30);
console.log(usersUnder30); 
1 Like

Thanks very much for your prompt response! This is really helpful to me! :blue_heart:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.