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
Post a Comment