logoalt Hacker News

predictand12/09/20244 repliesview on HN

I learned about Vacuous Truth the hard way recently when I found out that `every` method in JavaScript returns `true` for empty arrays as well.


Replies

marcosdumay12/09/2024

In programing, you can always rewrite that first rule as "all" and "some" must compose over set union. So, "all (A ∪ B) == all A && all B", and "some (A ∪ B) == some A || some B".

That lets you discover the answer for the empty set.

show 1 reply
crazygringo12/09/2024

As I think you would hope from a practical standpoint -- you don't want to have to handle a special case of false and always check if the array is empty.

I agree it's only logical in engineering contexts like that though, not in everyday language.

adamc12/09/2024

This is even what I expected, but I majored in math, so maybe that biased my response.

chiakic12/09/2024

But if you consider “liar” to be an object,

> liar.hats.every((hat) => hat.color === "green")

will throw a TypeError: Cannot read properties of undefined. That’s definitely not `true`.

show 4 replies