I've seen many people just write the compare function too complicated, yes sometimes maybe it's more readable, but sometimes it's just too long.
array.sort((a, b) => {
if (a > b) {
return 1;
}
if (a < b) {
return -1;
}
return 0;
});
array.sort((a, b) => a > b ? 1 : -1);
array.sort((a, b) => {
if (a.foo > b.foo) {
return 1;
}
if (a.foo < b.foo) {
return -1;
}
if (a.bar > b.bar) {
return 1;
}
if (a.bar < b.bar) {
return -1;
}
return 0;
});
array.sort(() => Math.random() > 0. 5 ? 1 : -1);
array.sort((a, b) => a - b);
array.sort((a, b) => a.localeCompare(b));
array.sort((a, b) => a.foo - b.foo || a.bar - b.bar);
array.sort(() => Math.random() - 0.5);
This rule should not fixable unless we are sure they are numbers.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too