Complete the code to check if the stack is empty.
isEmpty(): boolean {
return this.items.length [1] 0;
}The stack is empty when its length is exactly 0.
Complete the code to check if the stack is full given maxSize.
isFull(): boolean {
return this.items.length [1] this.maxSize;
}The stack is full when the number of items equals maxSize.
Fix the error in the isEmpty method to correctly check if stack is empty.
isEmpty(): boolean {
return this.items.length [1] 1;
}The original code incorrectly checks if length equals 1. The correct check is if length == 0 to check empty stack.
Fill both blanks to complete the method that returns true if stack is neither empty nor full.
isAvailable(): boolean {
return this.items.length [1] 0 && this.items.length [2] this.maxSize;
}The stack is available if length is greater than 0 and less than maxSize.
Fill all three blanks to create a method that returns the current size of the stack if it is not empty, else returns -1.
currentSize(): number {
if (this.items.length [1] 0) {
return this.items.length [2] 0 ? -1 : this.items.length;
} else {
return [3];
}
}The method checks if length is greater than 0, then uses a ternary to confirm length equals 0 or not, returning length or -1 accordingly. Else returns -1.
