开发者

Get difference of arrays in Ruby [duplicate]

开发者 https://www.devze.com 2023-03-30 03:52 出处:网络
This question already has answers here: Closed 11 years ago. 开发者_StackOverflow中文版 Possible Duplicate:
This question already has answers here: Closed 11 years ago. 开发者_StackOverflow中文版

Possible Duplicate:

diff a ruby string or array

I have an old array: [1, 2, 3, 4, 5], and new: [1, 2, 4, 6]

How to get difference with Ruby: that 5, 3 was removed and 6 was added?


irb(main):001:0> a = [1, 2, 3, 4, 5]
=> [1, 2, 3, 4, 5]
irb(main):002:0> b = [1, 2, 4, 6]
=> [1, 2, 4, 6]
irb(main):003:0> a - b
=> [3, 5]
irb(main):005:0> b - a
=> [6]
irb(main):006:0>
0

精彩评论

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

关注公众号