rails - Finding intersections between multiple arrays

后端 未结 3 2060
时光说笑
时光说笑 2021-01-30 12:19

I am trying to find the intersection values between multiple arrays.

for example

code1 = [1,2,3]
code2 = [2,3,4]
code3 = [0,2,6]

So the

3条回答
  •  故里飘歌
    2021-01-30 12:49

    Use the & method of Array which is for set intersection.

    For example:

    > [1,2,3] & [2,3,4] & [0,2,6]
    => [2]
    

提交回复
热议问题