Use the map Method to Extract Data from an Array not working on FCC

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/use-the-map-method-to-extract-data-from-an-array/
In codepen, this code-

var rating = [];
for(var i=0; i < watchList.length; i++){
  rating.push({title: watchList[i]["Title"],  rating: watchList[i]["imdbRating"]});
}

yields the same as this one-

let rating =  watchList.map(obj => {
   var rObj = {};
   rObj.rating = obj["imdbRating"];
   rObj.title = obj["Title"];   
   return rObj;
});

but the later won’t pass FCC test.
Can you assist me please?

Looks like title should come before rating.

1 Like

There you go.
Thank you!
edit: when you get close to get burned, you miss the stupid things…

Yeah, for some reason, the order matters. It shouldn’t (need to fix the test) but it does.

Also, your map callback is a little overkill. This would be simpler:

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

or better

let rating =  watchList.map(obj => ({ title: obj.Title, rating: obj.imdbRating }));
1 Like

Kevin, thank you.
Indeed one example of yours is better than the other. (needless to say, than my solution)

That’s cool. Yours works. You can drive a nail in with a frying pan, it doesn’t mean that it’s the best solution.

I would take a close look at the more standard solutions. If you presented yours to an interviewer, you would get some raised eyebrows. It looks like someone who isn’t comfortable with or doesn’t fully understand objects. Even:

   var rObj = {
     rating: obj.imdbRating,
     title: obj.Title
   }   
   return rObj;

would be an improvement. And I might even do this if I were debugging something.

It may seem picky, but I suggest it is best to learn to do things the “best” way. I know it’s confusing and there is a lot of information coming at you from 1000 directions, but that is what you are trying to learn.

Don’t get frustrated - we’ve all been where you are. I’m just trying to help you find the shortest path.

I know there’s a temptation to “just get something that works and move on.” Equally dangerous is “I’m not going to move on until I understand this 100% down to an atomic level”. The trick is finding a balance.

1 Like

I’m reading and re-reading your comment. And you’re absolutely right.
And is not picky. It’s how things are supposed to be done- nothing more and nothing less than right.
I used to get really anxious and frustrated spending weeks on challenges or lessons that I didn’t understand. Until I learned to move on and revisit them eventually, after the burn passed.

I’m not embarrassed to confess that I have a hard time understanding data structures and algorithms. Can’t stop to feel like I’m Tesla (the original) every time i see the FCC green check, though.

Anyway. I’m tireless. I’ll get it. Eventually.
Even if there are no more interviewers left that would care.

Thank you for taking your time with your post.

I’m not embarrassed to confess that I have a hard time understanding data structures and algorithms.

You shouldn’t be embarrassed at all. They can be tough. And everybody has different things with which they struggle.

Anyway. I’m tireless. I’ll get it. Eventually.

With that attitude, I have no doubt that you’ll get there. Keep up the good work.

1 Like