3 ms·
To be fair, let a = 0; for (const record of records) { if (record.bool){ a += 1; } } or ls.filter(x => x).length;
by Tarean 9y ago
To be fair,
let a = 0;
for (const record of records) {
if (record.bool){
a += 1;
}
}
or
ls.filter(x => x).length;
aren't that much harder to read. The second one probably doesn't do deforestation and would end up stupidly slow, though.
- xamuel 9y agoFor the first one, would engines like v8 be smart enough to optimize it so it isn't wasting time on a pointless if-branch? (I'd imagine not, as it would be pretty hard for the engine to know that all the record.bool's are booleans.)