如何在 ruby​​ 数组中找到整数/最大整数并返回索引位置? [英] How do I find a integer/max integer in an array for ruby and return the indexed position?

查看:62
本文介绍了如何在 ruby​​ 数组中找到整数/最大整数并返回索引位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我目前所拥有的

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

我如何花时间并对其应用一种方法来从中提取最大的整数并了解其索引位置.原因是我想知道名字中哪个人年龄最大.并行赋值阻碍了我对数组进行 .sort 的能力,因为它改变了与名称关联的元素的位置.

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,

推荐答案

ages.zip(names).max

这篇关于如何在 ruby​​ 数组中找到整数/最大整数并返回索引位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆