|
|
|
|
|
by XCSme
2265 days ago
|
|
I think you can just do: if (cellA > cellB) return 1;
if (cellA < cellB) return -1;
if (cellA === cellB) return 0;
Why is the switch better?
Or even (less explicit, but shorter code): if (cellA === cellB) return 0;
return cellA > cellB ? 1 : -1;
|
|
Your last version doesn't tell the reader what your intention is at all, and they need to work out what you're trying to do here. It's a lot less readable. Unless you're desperate for those bytes, it'd be better to use the switch statement for this case.
[0]: This gets a little weird in languages like JS where switch statements fall through to the next one if you don't break or return, but generally it still holds true.