Test name | Executions per second |
---|---|
flatMap | 4040.3 Ops/sec |
reduce with push | 15095.1 Ops/sec |
var arr = Array.from({length:10000}, (v, i) => ({name: i, assigned: Math.random() < 0.5}));
arr.flatMap((o) => (o.assigned ? [o.name] : []));
arr.reduce((a, o) => (o.assigned && a.push(o.name), a), [])