push()
method that pushes JavaScript objects at the top of the stack; and pop()
method, that removes the JavaScript object that's at the top of the stack at the current moment.
"BIO12"
is at the base, and "PSY44"
is at the top of the stack.
Modify the given array and treat it like a stack
using the JavaScript methods mentioned above. Remove the top element "PSY44"
from the stack. Then add "CS50"
to be the new top element of the stack.
homeworkStack
should only contain 4 elements.
testString: 'assert(homeworkStack.length === 4, "homeworkStack
should only contain 4 elements.");'
- text: The last element in homeworkStack
should be "CS50"
.
testString: 'assert(homeworkStack[3] === "CS50", "The last element in homeworkStack
should be "CS50"
.");'
- text: homeworkStack
should not contain "PSY44"
.
testString: 'assert(homeworkStack.indexOf("PSY44") === -1, "homeworkStack
should not contain "PSY44"
.");'
- text: The initial declaration of the homeworkStack
should not be changed.
testString: 'assert(code.match(/=/g).length === 1 && /homeworkStack\s*=\s*\["BIO12"\s*,\s*"HIS80"\s*,\s*"MAT122"\s*,\s*"PSY44"\]/.test(code), "The initial declaration of the homeworkStack
should not be changed.");'
```