Skip to main content
manishk0011
Inspiring
Sep 28, 2022 6:58 AM UTC
Question

Get the intersection of list of array

Hi All,

Can you please help me how to get the intersection of  Lists of array (number array). So I have a list of  number array which I construct in the interface. I need to only pick the common element  present in all the number array . I tried with loop and reduce function but not getting the actual result .

It has been achieved by taking an array element and loop over other other array and check if present in all array then keep it or remove it which I feel is very dirty way of doing . 

Any suggestion would be appreciated.

Thanks 

Manish

12 replies

stefanhelzle0001
Brainy
Sep 28, 2022 7:03 AM UTC
manishk0011
Inspiring
Sep 28, 2022 7:07 AM UTC

Hi Stefan,

I have tried intersection with reduce function but not able to achieve it as list of number array generate at runtime and I am not able to pass it like an arguments.

[{1,2,3},{2,3,4},{4,5,6}]

Thanks 

Manish

stefanhelzle0001
Brainy
Sep 28, 2022 7:10 AM UTC

Why do you need reduce to do that?

intersection({1,2,3,4},{2,3,4},{4,5,6})

returns 4, which is the only number present in all the arrays.