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

Can anyone help me with this code please.

Here is the code and break it down please piece by piece

var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];

const result = words.filter(word => word.length > 6);

console.log(result); // expected output: Array ["exuberant", "destruction", "present"]

question here what is that word => word.length>6; is that arrow function. line 2

1 Answer

Filter takes a predicate (something that returns True or False), you can pass in a function reference or an arrow function (usually called lambda function) to filter. So what it does is that it runs the arrow function on every item in the list (where "word" resembles the single item) and returns a new list where the function (in this case "word.length => 6") returns true.