psharma
psharma

Reputation: 1289

How to find which array element is not present in another

Here is the scenario

a = [1,2,3]
b = [2,5,6]

I would like to find out which elements of b are not present in a. I could use include? to check which ones are. But I am looking for something entirely opposite here.

Upvotes: 1

Views: 178

Answers (2)

Arup Rakshit
Arup Rakshit

Reputation: 118261

a = [1,2,3]
b = [2,5,6]
b - a #=> [5, 6]

Upvotes: 3

Dave Newton
Dave Newton

Reputation: 160171

> a - b
=> [1, 3]
> b - a
=> [5, 6]

(I can't quite tell which way you want to go.)

Upvotes: 8

Related Questions