Impossible to complete: Functional Programming: Use the filter Method to Extract Data from an Array

It appears that the page is testing for:
[{“title”: “Inception”,“rating”: “8.8”},{“title”: “Interstellar”,“rating”: “8.6”},{“title”: “The Dark Knight”,“rating”: “9.0”},{“title”: “Batman Begins”,“rating”: “8.3”}]
NOTE: there is a space after “:” before the quoted value
And there is no way to get this response with those spaces.
I’ve used:
As you did in the previous “map” lesson in order to get the quotes on the item name, but it does not add spaces where you have them indicated in your required response. Otherwise, my end array is identical.
[{“title”:“Inception”,“rating”:“8.8”},{“title”:“Interstellar”,“rating”:“8.6”},{“title”:“The Dark Knight”,“rating”:“9.0”},{“title”:“Batman Begins”,“rating”:“8.3”}]

Hello and welcome to the freeCodeCamp community,

I was able to pass this challenge on my end - could you share your current code?

1 Like

you need to return an array, not a string

can you share your code?

Here is my code:

let filteredList = => {return {'title':a.Title,'rating':a.imdbRating}});
filteredList = JSON.stringify(filteredList.filter(a => a.rating*1 >= 8.0));

Without the JSON.stringify, the output is:

[ { title: 'Inception', rating: '8.8' },
  { title: 'Interstellar', rating: '8.6' },
  { title: 'The Dark Knight', rating: '9.0' },
  { title: 'Batman Begins', rating: '8.3' } ]

Which while it should be technically correct, the test wants all items to be in double quotes.
Note that the previous lesson using map uses the JSON.stringify to get the correct result as well, although this lesson does not provide this already in the code as the map lesson does.

1 Like

I just removed the JSON.stringify:

let filteredList = => {return {‘title’:a.Title,‘rating’:a.imdbRating}}).filter(a => a.rating*1 >= 8.0);

to get this console output:

[ { title: ‘Inception’, rating: ‘8.8’ },
{ title: ‘Interstellar’, rating: ‘8.6’ },
{ title: ‘The Dark Knight’, rating: ‘9.0’ },
{ title: ‘Batman Begins’, rating: ‘8.3’ } ]

And it accepted this as a correct result.
Really counter intuitive for the lesson to alter the example output such that it does not match the actual result.
I’m also not sure why this works today, but I’m pretty darn sure this result was not accepted yesterday.

This is resolved.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

what do you mean? the example output is an object, and the accepted output is an object