Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,138 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
MOD
Cameron Childres
Treehouse Moderator 11,714 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,138 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
Treehouse Moderator 11,714 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.