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.
Seth MissiaenWeb Development Techdegree Graduate 19,908 Points
Another 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!
Steven Parker220,425 Points
Your 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.