开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜