gpt4 book ai didi

ruby - 从数组的数组中获取最后一个值

转载 作者:数据小太阳 更新时间:2023-10-29 07:42:38 25 4
gpt4 key购买 nike

arr = [[a,1], [b,3], [c,2]]

如何将上面的数组转换成下面的数组:

[1,3,2]

最佳答案

使用map & last :

arr.map(&:last)  #=> [1,3,2]

这相当于更长

arr.map { |o| o.last }

关于ruby - 从数组的数组中获取最后一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11111565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com