Good question. People will say blanket things like "for loops are always faster", but it -really- depends on every individual use case. So you might want to create solutions for each to the best of your ability, then benchmark them.
Here are a couple of the top solutions (one for switch statement, and one for for loops) benchmarked against each other: https://jsbench.me/e3lh84u45z/1
It seems like the switch statement solution is 11% faster, but you'll notice the for loop example has some regex bloat in there which is probably slowing it down.
Create your own clean solutions and benchmark them yourself. It's kinda fun.
Good question. People will say blanket things like "for loops are always faster", but it -really- depends on every individual use case. So you might want to create solutions for each to the best of your ability, then benchmark them.
Here are a couple of the top solutions (one for switch statement, and one for for loops) benchmarked against each other: https://jsbench.me/e3lh84u45z/1
It seems like the switch statement solution is 11% faster, but you'll notice the for loop example has some regex bloat in there which is probably slowing it down.
Create your own clean solutions and benchmark them yourself. It's kinda fun.
You're squareing it, not doubling it.
This comment is hidden because it contains spoiler information about the solution