Hi, I love this series. I always try to implement it by myself first.
Came up with a slight improvement of the push function:
// .... push(value) { const newNode = new Node(value); if (this.length) newNode.next = this.lastNode; this.lastNode = newNode; this.length++; return this; } // ...
I also like to return the whole object for the possibility of chaining the function:
const myStack = new Stack(); myStack .push("a") .push("b") .push("c");
Keep on doing this series. Love it! :-)
Hey Jannik,
thanks for your feedback, I appreciate it.
You are right, there is some duplication. I wanted to stay consistent with the Thoughts section, therefore I implemented it my way.
Thoughts
Greetings Michael
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi, I love this series. I always try to implement it by myself first.
Came up with a slight improvement of the push function:
I also like to return the whole object for the possibility of chaining the function:
Keep on doing this series. Love it! :-)
Hey Jannik,
thanks for your feedback,
I appreciate it.
You are right, there is some duplication.
I wanted to stay consistent with the
Thoughts
section,therefore I implemented it my way.
Greetings
Michael