forked from p15670423/monkey
ui: simplify compareOptions() with boolean arithmetic
This commit is contained in:
parent
117678f91a
commit
06685b14cf
|
@ -51,23 +51,14 @@ class AdvancedMultiSelect extends React.Component {
|
||||||
|
|
||||||
// Sort options alphabetically. "Unsafe" options float to the bottom"
|
// Sort options alphabetically. "Unsafe" options float to the bottom"
|
||||||
compareOptions = (a, b) => {
|
compareOptions = (a, b) => {
|
||||||
if (!this.isSafe(a.value) && this.isSafe(b.value)) {
|
// Apparently, you can use additive operators with boolean types. Ultimately,
|
||||||
return 1;
|
// the ToNumber() abstraction operation is called to convert the booleans to
|
||||||
|
// numbers: https://tc39.es/ecma262/#sec-tonumeric
|
||||||
|
if (this.isSafe(b.value) - this.isSafe(a.value) !== 0) {
|
||||||
|
return this.isSafe(b.value) - this.isSafe(a.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isSafe(a.value) && !this.isSafe(b.value)) {
|
return a.value.localeCompare(b.value);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a.value < b.value) {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a.value > b.value) {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMasterCheckboxClick = () => {
|
onMasterCheckboxClick = () => {
|
||||||
|
|
Loading…
Reference in New Issue