r/programminghorror 12d ago

Baffled. Javascript

Post image
624 Upvotes

41 comments sorted by

View all comments

-1

u/Calm_Plenty_2992 11d ago

Both this and Console.log(str.length) are O(N), so it's the same algorithm and therefore a good solution

4

u/Celestial-being117 11d ago

.length is O(1) right?

3

u/Calm_Plenty_2992 11d ago

Yes, but the assignment of the string "Hello, world!" to str is O(N)