push()方法;和pop()方法,它删除当前位于堆栈顶部的JavaScript对象。 "BIO12"位于基础, "PSY44"位于堆栈的顶部。修改给定的数组,并使用上面提到的JavaScript方法将其视为stack 。从堆栈中删除顶部元素"PSY44" 。然后添加"CS50"作为堆栈的新顶部元素。 homeworkStack应该只包含4个元素。
testString: 'assert(homeworkStack.length === 4, "homeworkStack should only contain 4 elements.");'
- text: homeworkStack的最后一个元素应该是"CS50" 。
testString: 'assert(homeworkStack[3] === "CS50", "The last element in homeworkStack should be "CS50".");'
- text: homeworkStack不应包含"PSY44" 。
testString: 'assert(homeworkStack.indexOf("PSY44") === -1, "homeworkStack should not contain "PSY44".");'
- text: 不应更改homeworkStack的初始声明。
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.");'
```