Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
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.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: