#vanilla javascript
Paul Ryan
Jun 4, 2021 ⋅ 10 min read

Know your JavaScript data structures

Paul Ryan Developer hailing from Ireland. Loves all things JS and also starting to fall in love with SVGs!

Recent posts:

Vite Adoption Guide Overview Examples And Alternatives

Vite adoption guide: Overview, examples, and alternatives

Vite is a versatile, fast, lightweight build tool with an exceptional DX. Let’s explore when and why you should adopt Vite in your projects.

David Omotayo
Nov 29, 2023 ⋅ 16 min read
Implementing Advanced Features With The Navigator.Share API

Implementing advanced features with the navigator.share API

Explore advanced capabilities for content sharing with the navigator.share API, including dynamic content sharing, custom share targets, and batch sharing.

David Omotayo
Nov 29, 2023 ⋅ 10 min read
Chas Peacock Leader Spotlight

Leader Spotlight: Scaling for the next phase of growth with Chas Peacock

We spoke with Chas to get his insights on building technology and internal processes for companies that are scaling quickly.

Jessica Srinivas
Nov 29, 2023 ⋅ 7 min read
Cypress Adoption Guide: Overview, Examples, Alternatives

Cypress adoption guide: Overview, examples, and alternatives

Cypress is one of today’s foremost tools for testing web applications. Let’s explore when and why you should adopt Cypress in your projects.

Paul Akinyemi
Nov 28, 2023 ⋅ 10 min read
View all posts

7 Replies to "Know your JavaScript data structures"

  1. Stack implementation has few errors.
    For example try this code:
    var stack = new Stack();
    stack.peek(); // –> 1
    stack.peek(); // –> undefined, because this._length became -1
    Same problem with pop() method – you decrement this._length three times

  2. `–this.length` is used in error 3 times – decrementing the values instead of retrieving the position. It’s a pretty fundamental error for a data structures tutorial

  3. Hi, in Linked list when I want to remove last node(which is tail), the value of tail stays the same even if it’s deleted. Would this be good way to chage value of the tail? Im still learning.

    if(currentNode === this.tail){
    this.tail = previousNode;
    previousNode.next = currentNode.next;

  4. There’s a few bugs in the Queue implementation e.g. the `dequeue()` method doesn’t have a `return` statement, so the `firstVal` isn’t returned. If `enqueue(val)` is called multiple times the length can become a negative number, meaning subsequent `peek()` calls return undefined, even after adding values

  5. I updated the article to use an array for the queue, as a note though you wouldn’t use `push` you would use `unshift`

Leave a Reply