如何在 ruby​​ 数组中找到整数/最大整数并返回索引位置?

编程入门 行业动态 更新时间:2024-10-26 16:34:15
本文介绍了如何在 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​​ 数组中找到整数/最大整数并返回索引位置?

本文发布于:2023-11-30 12:19:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649924.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:整数   数组   索引   位置   中找到

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!