top | item 44245850

(no title)

barbegal | 8 months ago

In each loop prepending a single character could take O(m) (moving all m characters one to the right) so combined O(nm) where n is the number of padding characters and m is the total number of characters in the string.

discuss

order

lifthrasiir|8 months ago

Only when the underlying JS implementation does this naively. In reality JS implementations do a lot of optimizations which often can reduce the time complexity.

bondarchuk|8 months ago

"The compiler will take care of it", funny, heard that one before, I'd profile it just to be on the safe side...