4 ms·
The 0 and 1 are completely unnecessary though in some of these. Example is_same_variable(exp, variable) ? 1 : 0 If is_same_
by vorticalbox 3y ago
The 0 and 1 are completely unnecessary though in some of these.
Example
is_same_variable(exp, variable)
? 1
: 0
If is_same_variable returns a truthy value then return 1 else 0.
We can remove that and it will still follow the same while also being more readable
- Jtsummers 3y agoIt’s calculating the derivative. 0 and 1 aren’t used for their truthiness, but as values. d/dx x becomes 1 and d/dx y becomes 0 (the two cases, same variable and different variable).
- vorticalbox 3y agoJavaScript will coerc the types. 1+1 and true+true both = 2
- Jtsummers 3y agoSo you've gone from "nested ternary is hard to read" to "This is an introductory text, let's mix arithmetic with numbers and booleans by using true and false for 1 and 0"? That's a remarkable turn in just a few comments toward the side of obfuscation.
- 3cats-in-a-coat 3y agoI'm not trying to change the code, I'm only formatting it.