David said:
Garrett Smith wrote:
[...]
I just don't care to evaluate the length property each time through (or
to splice one member at a time), even in an example. And though
slightly longer, I consider mine to be easier to understand at a glance.
It is not surprising that you would find your solution easier to
understand; you wrote it. However, it is longer and more complicated.
Although the while loop was very fast, it was not as fast as the for loop.
Cyclomatic complexity is number of decisions +1.
The while-loop based function has a while loop, a nested while loop, and
two decisions: `if` and ternary `?`. It has a count of 5.
The for loop with one decision has a count of 3.
If I am wrong about the cyclomatic complexity calculation, somebody
please correct me.
Neither are very complicated, but the for loop is shorter, simpler, and
more straightforward. It wins by a small margin.
The array filter approach not as fast, as is to be expected, however it
is the simplest of all, with cyclomatic complexity of 2.