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

Sorting object array

How would you print out the highest grade and youngest age in this object array without using the sort function in javascript. Preferable a search algorithm . Please help. Thank you. var person = [ {person: "Henry", age: "20", grade:"A"} {person: "Katie", age:"21", grade:"B"} ];

1 Answer

Steven Parker
Steven Parker
243,318 Points

This would be a good place to use "reduce()". But if you're not familiar with it, you could write a loop that goes through every item, and compares each age and grade against a saved minimum value of each, and replaces the saved value if the current one is lower.

Hopefully you can get it from these hints.
I don't like to give spoilers in general, but I'd also be afraid I'm doing your homework. :smirk:

Thanks Steven, your lead helps.