The exception would be if the more "complex" solution was more performant.
For verification, I ran a perf test on the two funcs, and the switch idiom won out. (see screenshot below).
If another idiom were to beat out the switch idiom, I would swap out the implementation for the fastest idiom that uses the least cycles.
Wrap it in a function, document it, and include a resource link to the performance notes, tests and reasoning of the chosen implementation.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is a case where the switch block is probably the simplest idiom with the least cognitive load.
Having to use Math.min, conditional Regex's, replace callbacks, and array shifts, would be unnecessary complexity.
Good work showing the variants to outline the pros and cons though.
The exception would be if the more "complex" solution was more performant.
For verification, I ran a perf test on the two funcs, and the switch idiom won out. (see screenshot below).
If another idiom were to beat out the switch idiom, I would swap out the implementation for the fastest idiom that uses the least cycles.
Wrap it in a function, document it, and include a resource link to the performance notes, tests and reasoning of the chosen implementation.