Hacker News new | past | comments | ask | show | jobs | submit login

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.



For 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.)




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: