0

I know that slice has time complexity of O(n) and so I wanted to know if its possible to remove the last character of string in JavaScript in Constant time?

For arrays we have pop method that I assume is Constant time however if I convert the string to array and then convert it back to string that would again mean O(N) which is linear time.

What's the difference between slice and substr method? Which is more performant? Why do we need substring when we already have slice?

Shivam Sahil
  • 4,055
  • 3
  • 31
  • 62
  • Please visit the [help], take the [tour] to see what and [ask]. - make sure to [do some research](https://www.google.com/search?q=slice+vs+substring+performance). If you get stuck, post a [mcve] of your attempt, noting input and expected output using the [\[<>\]](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) snippet editor. – mplungjan Oct 04 '22 at 13:55

0 Answers0