Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
Tarean
on Sept 9, 2017
|
parent
|
context
|
favorite
| on:
JavaScript: The Curious Case of null >= 0
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
on Sept 10, 2017
[–]
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.)
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: