如何获得包含相同元素的两个数组的交集?

时间:2016-12-01 21:45:33

标签: arrays ruby

apple = ["a","p","p"]
zebra = ["a","p","p","l","e"]
apple & zebra
# returns => ["a", "p"]

我想要一个能够返回[" a"," p"," p"]

的函数

有没有办法可以做到这一点?

0 个答案:

没有答案