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 JavaScript Array Iteration Methods Array Manipulation Return a Single Value from an Array with reduce()

Seth Missiaen
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Seth Missiaen
Web Development Techdegree Graduate 21,652 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!

1 Answer

Steven Parker
Steven Parker
231,248 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. :+1: