E
E
eldar_web2015-10-20 14:37:46
Ruby on Rails
eldar_web, 2015-10-20 14:37:46

How in Ruby from two arrays it is possible to display non-matching values?

I can't solve this problem at all.
The fact is that, for example, there are arrays:

list = [101,102,103,104,105]
list2 = [101,102,103]

I want to compare these arrays and display non-matching values, i.e. those values ​​that are in list, but not in list2, in our case it is 104, 105.
How can this be done?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Tkachenko, 2015-10-20
@eldar_web

list = [101,102,103,104,105]
=> [101, 102, 103, 104, 105]
list2 = [101,102,103]
=> [101, 102, 103]
(list-list2) | (list2-list)
=> [104, 105]

A
Alexey Ukolov, 2015-10-20
@alexey-m-ukolov

lmgtfy:
ruby-doc.org/core-2.2.0/Array.html#2D-method
grosser.it/2011/07/07/ruby-array-diffother-differe...
stackoverflow.com/questions/80091/diff -a-ruby-stri...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question