Creating a JavaScript object-based Stack class
The easiest way of creating a Stack class is using an array to store its elements. When working with a large set of data (which is quite common in real-world projects), we also need to analyze what is the most efficient way of manipulating the data.
When reviewing the efficiency of our array-based Stack
class, we learned that some JavaScript engines might use hash tables to implement an array. We have not learned hash tables yet, but we can implement a Stack class using a JavaScript object to store the stack elements, and by doing so, we can access any element directly, with time complexity O(1). And of course, comply with the LIFO principle. Let's see how we can achieve this behavior.
We will start by declaring the Stack class (src/04-stack/stack-object.js
 file) as follows:
class Stack {
#items = {}; // {1}
#count = 0; // {2}
// other methods
}
For this version of the Stack
 class, we will use...