ui: simplify compareOptions() with boolean arithmetic

This commit is contained in:
Mike Salvatore 2021-01-29 10:52:14 -05:00
parent 117678f91a
commit 06685b14cf
1 changed files with 6 additions and 15 deletions

View File

@ -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 = () => {