Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find a integer/max integer in an array for ruby and return the indexed position?

Tags:

ruby

This is what I have so far

ages   = [20,19,21,17,31,33,34]
names  = [Bob, Bill, Jill, Aimee, Joe, Matt, Chris]

How do I take ages and apply a method to it to extract the largest integer out of it and learn its indexed position. The reason being I want to know which person in names is the oldest. Parallel assignment is blocking my ability to do a .sort on the array becasue it changes the position of element associted with names.

Please include code to mull over thanks,

like image 216
Matt Avatar asked Dec 08 '22 05:12

Matt


1 Answers

ages.zip(names).max
like image 102
jrhicks Avatar answered May 20 '23 15:05

jrhicks