Hacker News new | past | comments | ask | show | jobs | submit login
Why does every() return true for empty arrays? (humanwhocodes.com)
1 point by corentin88 on Sept 13, 2023 | hide | past | favorite | 3 comments



I don't understand why this behavior is surprising to anybody. If you have a list of three things, the condition must be met for three things. Likewise for a list of two things, the condition must be met for two things. The pattern holds for one thing, and zero things.


While JS might be "unexpected" sometimes, I like very much that the reason behind this behavior is a mathematical concept.


The alternative (breaking !every([], !f(x)) == some([], f(x))) is worse.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: