开发者

Ruby: is there a way to get the values from an array using an array of indexs all in one line?

开发者 https://www.devze.com 2023-02-08 03:00 出处:网络
array: [1,2,1,1,2,2,2,1,1,1,1,1] index开发者_StackOverflow中文版es: [0,3,5,1] output: [1,1,2,2] output = array.values_at(*indexes)
array: [1,2,1,1,2,2,2,1,1,1,1,1]
index开发者_StackOverflow中文版es: [0,3,5,1]
output: [1,1,2,2]


output = array.values_at(*indexes)

Note that you have to splat the indexes argument, values_at accepts a list of integers or ranges as argument

0

精彩评论

暂无评论...
验证码 换一张
取 消