最好的方式在多个阵列迭代? [英] Best way to iterate over multiple arrays?

查看:106
本文介绍了最好的方式在多个阵列迭代?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最好的(美容,高效的在性能方面)的方式来多个阵列迭代在Ruby中?
比方说,我们有一个数组:

What's is the best (beauty and efficient in terms of performance) way to iterate over multiple arrays in Ruby? Let's say we have an arrays:

a=[x,y,z]
b=['a','b','c']

和我想这样的:

x a
y b
z c

感谢。

推荐答案

拉链对数组对象的方法:

a.zip b do |items|
    puts items[0], items[1]
end

这篇关于最好的方式在多个阵列迭代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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