Update step2-04 exercises

This commit is contained in:
Elizabeth Craig
2019-02-28 15:22:20 -08:00
parent 4e9257e564
commit 632bb4f210
3 changed files with 27 additions and 13 deletions

View File

@@ -1,13 +1,27 @@
export class Stack<T> {
private _items: T[] = [];
/** Add an item to the top of the stack. */
push(item: T) {
this._items.push(item);
}
/** Remove the top item from the stack and return it. */
pop(): T {
if (this._items.length > 0) {
return this._items.pop();
}
}
/** Return the top item from the stack without removing it. */
peek(): T {
if (this._items.length > 0) {
return this._items[this._items.length - 1];
}
}
/** Get the number of items in the stack/ */
get count(): number {
return this._items.length;
}
}