DEV Community

Discussion on: Daily Challenge #266 - Who Likes It?

Collapse
 
functional_js profile image
Functional Javascript

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.

Collapse
 
functional_js profile image
Functional Javascript

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.

Alt Text