2021-06-04
2977
#vanilla javascript
Paul Ryan
9379
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:

Comparing Hattip Vs Express Js For Modern Application Development

Comparing Hattip vs. Express.js for modern app development

Explore what Hattip is, how it works, its benefits and key features, and the differences between Hattip and Express.js.

Antonello Zanini
May 2, 2024 â‹… 8 min read
Using React Shepherd To Build A Site Tour

Using React Shepherd to build a site tour

React Shepherd stands out as a site tour library due to its elegant UI and out-of-the-box, easy-to-use React Context implementation.

Onuorah Bonaventure
May 1, 2024 â‹… 14 min read
A Guide To Cookies In Next Js

A guide to cookies in Next.js

Cookies are crucial to web development. This article will explore how to handle cookies in your Next.js applications.

Georgey V B
Apr 30, 2024 â‹… 10 min read
Handling Dates In JavaScript With Tempo

Handling dates in JavaScript with Tempo

Use the Tempo library to format dates and times in JavaScript while accounting for time zones, daylight saying time, and date internationalization.

Amazing Enyichi Agu
Apr 30, 2024 â‹… 8 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.push(1);
    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;
    return;
    }

  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