DEV Community


Discussion on: Basic JavaScript Interview Questions

jperasmus profile image
JP Erasmus

Using shift/unshift for the stack would not be a very efficient solution when using JS arrays under the hood because that would turn an O(1) action into O(n) since every item in the array would have to update its index every time to perform either of these actions. Pushing onto the end or popping from it is O(1) since only a single item is affected.

recursivefaults profile image
Ryan Latta

Being able to talk about that makes a better interview.