Oh so what makes shift() and unshift() O(n) is because of the change in the index they cause for elements in the array and not because they affect a single element at a known index?
Yes, main reason is mutation place: beginning of an array. Adding or removing an element from start changes index order of all other elements coming after it.
Oh so what makes shift() and unshift() O(n) is because of the change in the index they cause for elements in the array and not because they affect a single element at a known index?
Yes, main reason is mutation place: beginning of an array. Adding or removing an element from start changes index order of all other elements coming after it.
Thanks Sahin
this is a super important point :-) thanks!