getify / You-Dont-Know-JS

A book series on JavaScript. @YDKJS on twitter.
Other
177.86k stars 33.39k forks source link

IsLessThan wrong output #1848

Closed paimfp closed 8 months ago

paimfp commented 8 months ago

I already searched for this issue.

Edition: 2nd

Book Title: types-grammar

Chapter: ch4.md

Section Title: Relational Comparison

Problem:

In the second example we have:

IsLessThan(1,2, /*LeftFirst=*/ true );            // true

// equivalent of a fictional "IsGreaterThan()"
IsLessThan(2,1, /*LeftFirst=*/ false );          // false

in the second expression, the order of arguments were changed and LeftFirst is false.

If I understood it correctly, that basically means IsGreaterThan(2, 1). And 2 is greater than 1, it should be true not false.

Another options would be like so (Change just the LeftFirst argument):

IsLessThan(1,2, /*LeftFirst=*/ false ); // false

getify commented 8 months ago

The example in the book is correct... here's why:

It's important to note that this is all meta (illustrative, not prescriptive) since these abstract operations don't actually exist as real functions to call; moreover, passing a boolean argument to a function as shown wouldn't actually have controlled the order of computation for the other previous arguments being passed.