Hint or further reading to findTheOldest exercise

Hi all,

I am working through the JS exercises and hit a brick wall when I got to findTheOldest.

The coursework thus far has been extensive and I may have missed it, but I do not recall learning and practicing the tools needed to solve this one. The readme mentions using array.reduce() or filter.

Looking into these on my own, I am down a rabbit hole about filter, map, reduce, looping arrays (some loops ignore non-numerical, etc.). The previous few exercises (Caesar, Fibonacci, calculator, temp conversion, etc.) took me anywhere from a day to just a few minutes. This one (findTheOldest) has stumped me for days and I cannot get any traction.

Could someone advise on specific readings or practice exercises to allow me to learn/use the tools to solve this type of array manipulation?

Thanks for your patience and assistance,

Hi, here is the Web Bos video if you missed it.

Basicaly reduce aplies to each element of the array returning only one element.

 array.reduce((oldest,current) => { 

for each element in the array (current), the function only returns one value,
this value returned is the first parameter (oldest) passed to the fuction in the next iteation.

But the first element in the array doesnt have a previous element, in that case the oldest parameter doesnt have any value.
Here comes initial. Is the value oldest when the function is aplied to the first element of the array.

When the array ends the final value is the last value returned.

So the only thing you need is compare the ages between oldest and current and return the element you want. You can put as initial the first element of the array.

Hope this will help.

This is perfect - thank you!!!

Follow up (Warning: Dumb question)… In the video, he is using an embedded console with the IDE. I am using VSCode on Mac. Do you know how I can get a simple console working on that to follow along his exercises?

Hi, he is using the browser console, and VSCode in the other side of the screen.

Maybe is confusing because it seems is another program. But he put the browser console in full size, since it is the only part of the browser he needs.

To make the page autorefresh each time the code is changed you can add to VSCode the Live Server plugin. Here is a tutorial. Of course the console also autorefresh.

You’re awesome. You basically got me unstuck from the mud. Cheers!

1 Like