turning the customslider handle change function from an if else if statement to a switch statement
the switch statement is faster in most cases when compared to if-else, but significantly faster only when the number of conditions is large. And It would help to make it more readable
Screenshots
No response
Additional information
const handleChange = (value) => {
//reset
switch (true) {
case isNaN(value):
value =
profile === 'truck'
? settingsInitTruckOverride[option.param]
: settingsInit[option.param];
break;
case value < min:
value = min;
break;
case value > max:
value = max;
break;
default:
break
}
Description
turning the customslider handle change function from an if else if statement to a switch statement
the switch statement is faster in most cases when compared to if-else, but significantly faster only when the number of conditions is large. And It would help to make it more readable
Screenshots
No response
Additional information
const handleChange = (value) => { //reset switch (true) { case isNaN(value): value = profile === 'truck' ? settingsInitTruckOverride[option.param] : settingsInit[option.param]; break; case value < min: value = min; break; case value > max: value = max; break; default: break }