javascript - Filtering an Array based on another Boolean array -


say have 2 arrays:

const data = [1, 2, 3, 4] const predicatearray = [true, false, false, true] 

i want return value be:

[1, 4] 

so far, have come with:

pipe(   zipwith((fst, scnd) => scnd ? fst : null)),   reject(isnil)  )(data, predicatearray) 

is there cleaner / inbuilt method of doing this?

solution in ramda preferred.

if want ramda solution reason, variant of answer richsilv simple enough:

r.addindex(r.filter)((item, idx) => predicatearray[idx], data) 

ramda not include index parameter list function callbacks, reasons, addindex inserts them.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -