I have two arrays [a,b,c,d]and [b,d,f,h].
I want to return an array with common elements [b,d].
I can achieve this with a combination of filterand indexOf:
[a,b,c,d].filter(el => [b,d,f,h].indexOf(el) !== -1)
but I was wondering how and how I can do the same with reduce.
I admit that, despite many examples, reduceit is still one of the most obscure JS methods, so I would really appreciate some advice.
source
share