April 2018
Beginner to intermediate
426 pages
10h 19m
English
And we are done! Our Queue class is implemented. Just like we did for the Stack class, we can also add the toString method:
toString() { if (this.isEmpty()) { return ''; } let objString = `${this.items[this.lowestCount]}`; for (let i = this.lowestCount + 1; i < this.count; i++) { objString = `${objString},${this.items[i]}`; } return objString;}
In the Stack class, we started to iterate the items values from index zero. As the first index of the Queue class might not be zero, we start iterating it from the lowestCount index.
And now we are really done!