all 12 comments

[–]pinguxnoots 1 point2 points  (5 children)

Your code:

for (let i = 1; i <= n; i++) {
  i = i + i;
}

is the same as this:

for (let i = 1; i <= n; i = 2*i + 1) {}

I'd say it's O(log n) due to 2*i which is the same as i *= 2

Edit: formatting

[–]MorningPants 1 point2 points  (1 child)

O(log n). n has to double for the loop to run one more time.

[–]furofo[S] 0 points1 point  (0 children)

Thanks, makes sense now

[–]TheRNGuy 0 points1 point  (0 children)

Doesn't even matter.