+ 1

Why compare work so?

We have consistence (c>b>a), where a=10, b=20, c=30 https://code.sololearn.com/W5gYyDvJN93O/?ref=app

9th Jul 2019, 2:30 PM
Knozi
Knozi - avatar
3 odpowiedzi
+ 1
This is how the code works c > b > a can be written like this (c > b) > a The (c > b) will return either true or false which has the value of 1 and 0 respectively. The c > b condition is true, so it becomes like this 1 > a, which is false, thus it prints 2
9th Jul 2019, 3:02 PM
Agent_I
Agent_I - avatar
+ 3
I'm not sure chained comparison operator like that works for JS, I only know it works in Python. In JS multiple expressions evaluation is chained using logical operator, so `if (c>b>a)` could be written as `if (c > b && b > a)` as I understand it. Hth, cmiiw
9th Jul 2019, 3:16 PM
Ipang
+ 1
First comments was right, check code
9th Jul 2019, 3:34 PM
Knozi
Knozi - avatar