Use the filter Method to Extract Data from an Array - double output after Run the Tests

Tell us what’s happening:

Why after Run the Tests i have the output printed double time?
Thank You
Bart

Console before clicking Run the Tests:

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

Console after clicking Run the Tests:

// running tests

filteredList

should equal

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

. // tests completed // console output
 [ { title: 'Inception', ratings: '8.8' },
 { title: 'Interstellar', ratings: '8.6' },
 { title: 'The Dark Knight', ratings: '9.0' },
 { title: 'Batman Begins', ratings: '8.3' } ]
 [ { title: 'Inception', ratings: '8.8' },
 { title: 'Interstellar', ratings: '8.6' },
 { title: 'The Dark Knight', ratings: '9.0' },
 { title: 'Batman Begins', ratings: '8.3' } ]

Your code so far

const filteredList = watchList
    .filter(e => e.imdbRating >= 8.0)
    .map(e => ({
                title: e.Title,
                ratings: e.imdbRating
            }));

Hello @uosiua

I’m not sure why but I assume that as you make edits on the editor, the code gets executed automatically → This explains the first console log. When you run the tests eventually, you initiate running the code again which explains the second console log.

I think that’s why.

Hello @alekskimeu,

The first console log is ok, that is in all the lessons, but for the first time i have the issue after running the test, and it can not pass because of that.

The problem is not the console.log() statement. It’s not passing because you haven’t wrapped the object’s properties in quotes. I just ran the tests on my end and it’s passing. Try that out.

The problem was that I created object as:

.map(e => ({
title: e.Title,
ratings: e.imdbRating
}));

instead of

.map(e => {
return {
title: e.Title,
rating: e.imdbRating
};
});

Thank you.

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