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 trialSeth Missiaen
Web Development Techdegree Graduate 21,652 PointsAnother solution to total names that start with "G"
I think the point of this video was to utilize the .reduce()
method, but I did find another solution that was much more concise:
const gNames = names.filter(names => names.charAt(0) === 'G').length;
I felt that length was more intuitive, but is there a reason I would want to use .reduce()
in this scenario instead? Does one require more processing power than the other? Thanks!
1 Answer
Steven Parker
231,236 PointsYour method is more concise and more efficient, but as you noted this was intended to be an illustration of how to use reduce.
But still, the fact that you're already thinking of ways to optimize code is evidence of your learning progress and grasp of the material.