Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Array Iteration Methods Combining Array Methods Combining filter() and map()

Jordan Kittle
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jordan Kittle
Full Stack JavaScript Techdegree Graduate 20,147 Points

This lesson never taught about wrapping an object literal in parenthesis to tell JavaScript to treat it as a literal.

I'm getting a little frustrated with Joel asking me to do things when the instruction didn't provide me with the necessary tools to do them.

1 Answer

Cameron Childres
Cameron Childres
11,817 Points

Hi Jordan,

From the video starting at 1:57 --

There is an issue that pertains to arrow functions. Because they use curly braces to surround their function bodies, the arrow function doesn't know this is an object literal, which also uses curly braces. I need to surround this object with parenthesis. That's just to tell JavaScript that I want to return this object literal from the callback.

https://teamtreehouse.com/library/combining-filter-and-map

If you need further clarification let me know and I'll do my best to help out.

Jordan Kittle
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jordan Kittle
Full Stack JavaScript Techdegree Graduate 20,147 Points

Hi Cameron,

He explains this after he asks you to pause the video and figure it out on your own. When I am asked to try something on my own, I would prefer to have all the information necessary to tackle the task. Instead I am getting stuck wondering why I can't do something only to find out brand new information after unpausing the video.

Cameron Childres
Cameron Childres
11,817 Points

Ah, my mistake! I read your post as referring to the lesson as a whole. I see how that could be frustrating.

I agree that this one is a bit obscure and could benefit from a mention earlier in the video or the teacher's notes about returning objects from arrow functions. This information isn't necessary for the solution though, since you can just use a regular function:

const userNames = ['Samir', 'Angela', 'Beatrice', 'Shaniqua', 'Marvin', 'Sean'];
    // Result: [{name: 'Samir'}, {name: 'Shaniqua'}, {name:'Sean'}];

let users = userNames
  .filter(name => name.charAt(0) === 'S')
  .map(function(name){
    let obj = {name};
    return obj;
  });

console.log(users);

Just to add a different perspective -- I often find moments like this to be valuable learning experiences. If the way I think it should work doesn't quite do it I'll seek out documentation or search online to figure out what I'm missing. If I can't (or just don't want to) figure it out myself I can always proceed to the teacher's solution. Seeking out solutions myself tends to help the concepts sink in better and provides useful practice for when I'm trying to solve issues I run in to on my own outside of the courses here.

Joe Elliot
Joe Elliot
5,330 Points

Totally agree, with both of you. While frustrating at times, for the most part this a valuable learning experience. I like how sometimes with Treehouse challenges I have to seek the answer out elsewhere before progressing with the video. It feels like how a real programmer would tackle a challenge.

I've used other learning resources that never push you to do this, and I retain nothing from the experience.