I have two arrays and i want to get all items which are NOT common to
both, so basically if i have two arrays A and B, i want all elements
in A that are not in B. what is the best way to do this apart from
using two nested loops.
thanks
rahtha
I have two arrays and i want to get all items which are NOT common to
both, so basically if i have two arrays A and B, i want all elements
in A that are not in B. what is the best way to do this apart from
using two nested loops.
thanks
rahtha
On Feb 16, 7:10 am, rahtha [email protected] wrote:
I have two arrays and i want to get all items which are NOT common to
both, so basically if i have two arrays A and B, i want all elements
in A that are not in B. what is the best way to do this apart from
using two nested loops.
A - B ?
On Tue, Feb 16, 2010 at 8:10 AM, rahtha [email protected] wrote:
I have two arrays and i want to get all items which are NOT common to
both, so basically if i have two arrays A and B, i want all elements
in A that are not in B. what is the best way to do this apart from
using two nested loops.
But do you want the ones in B that are not in A as well? (symmetric
difference)
Nope don’t care about that case just the ones in A that are not in B
rahtha wrote:
Nope don’t care about that case just the ones in A that are not in B
Well, then it’s what Frederick said.
irb(main):065:0> a = [1,2,3]
=> [1, 2, 3]
irb(main):066:0> b = [2,4,6]
=> [2, 4, 6]
irb(main):067:0> a-b
=> [1, 3]
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs