4 ms·
The do and while loops are unfair comparisons they should have done something like this: var i = items.length; while(i--) { total += items[i]; } and var i
by drunken_thor 13y ago
The do and while loops are unfair comparisons they should have done something like this:
var i = items.length;
while(i--) {
total += items[i];
}
and
var i = items.length - 1;
do {
total += items[i]
} while(i--);
I think those would compare differently to the for loop.
Turns out I was wrong and I made the for loop faster: http://jsperf.com/optimal-loops http://jsperf.com/optimal-loops
- jdmichal 13y agoI believe that do-while will also miss summing the item at index 0.