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.
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
Alexander Neldefors7,400 Points
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.