4 ms·
What you're writing here is equivalent to insisting that people do: if (a < b) { return -1; } else { if (a > b) { return 1; } else {
by atq2119 8y ago
What you're writing here is equivalent to insisting that people do:
if (a < b) {
return -1;
} else {
if (a > b) {
return 1;
} else {
return 0;
}
}
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]
- kazinator 8y agoNope, since I haven't added any non-whitespace characters, rather it is like insisting that people do: if (a < b) { return -1; } else if (a > b) { return 1; } else { return 0; } Unlike your perfectly formatted code there, this has a bit of a visual problem: a one-liner consequent is fully braced, whereas a multi-line alternative isn't. Ternary operators are different. They have confusing nesting and do not support the equivalent of the "if/else ladder" pattern very well.