3 ms·
JavaScript WTF: Why does every() return true for empty arrays? – Human Who Codes
- bhaney 3y ago> It is vacuously true that all elements of the empty set satisfy any given condition That could have been the entire article. Everything else is just fluff.
- 082349872349872 3y agoit didn't even include useful fluff, like: every xs ∧ every ys == every (xs \concat ys) every [] ∧ every [True] == every ([] \concat [True]) every [] ∧ every [True] == every [True] every [] ∧ True == True every [] == True
- DemocracyFTW2 3y ago> That could have been the entire article As for me, except for this: Instead of reading every() as “does every item in this array match this condition?” read it as, “is there any item in this array that doesn’t match this condition?” That shift in thinking can help avoid errors in your JavaScript code going forward. When I last had to implement an `all_of( collection, test )` functionality, I was stumped as for the edge case of an empty collection, until I realized that I wanted `all_of( c, t )` to behave exactly like `none_of( c, nt )` with `nt = ( x ) -> not t( x )`
- pestatije 3y agotoday there were no assignments...Charly, did you do all your homework? yes mum