Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有数组 [1, 2, 5],[1, 2, 3] 我想提取匹配值,如果有这样的方法:
[1, 2, 5]
[1, 2, 3]
[1, 2, 5].match([1, 2, 3]) #=> [1, 2]
有没有关于数组的方法,谢谢
很简单:
[1,2,5] & [1,2,3] #=> [1,2]
其他有用的数组操作包括:
[1,2,3] | [1,3,4] #=> [1,2,3,4] [1,2,3] - [1,3,4] #=> [2] [1,2,3] + [1,3,4] #=> [1,2,3,1,3,4]