You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
following part of code does nothing and can be (should be?) removed / commented out:
for (let i = this._count; i < this._items.length; i++) {
this._items[i] = this._items[i + 1];
}
Because it takes LAST element of array (which should be removed/popped out of array), then takes NEXT element (which apparently, doesn't exist, so it takes undefined), makes last element undefined and on next line of code this element is sliced out (and all the required job is actually done here):
this._items.length = this._count;
Whole this loop runs exactly ONCE (because its starting and ending points are next to each other) and doesn't really "shift left" anything.
It seems more like part of code for Queues data structure, but in wrong conditions..
Nice course anyway, thank you!
The text was updated successfully, but these errors were encountered:
https://github.com/bradtraversy/javascript-sandbox/blob/main/17-iterators-data-structures/08-stacks/script.js
following part of code does nothing and can be (should be?) removed / commented out:
Because it takes LAST element of array (which should be removed/popped out of array), then takes NEXT element (which apparently, doesn't exist, so it takes undefined), makes last element undefined and on next line of code this element is sliced out (and all the required job is actually done here):
this._items.length = this._count;
Whole this loop runs exactly ONCE (because its starting and ending points are next to each other) and doesn't really "shift left" anything.
It seems more like part of code for Queues data structure, but in wrong conditions..
Nice course anyway, thank you!
The text was updated successfully, but these errors were encountered: