2.7 KiB
2.7 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d8250367417b2b2512c5e | Learn how a Stack Works | 1 | 了解堆栈的工作原理 |
Description
push()
方法;和pop()
方法,它删除当前位于堆栈顶部的JavaScript对象。 Instructions
"BIO12"
位于基础, "PSY44"
位于堆栈的顶部。修改给定的数组,并使用上面提到的JavaScript方法将其视为stack
。从堆栈中删除顶部元素"PSY44"
。然后添加"CS50"
作为堆栈的新顶部元素。 Tests
tests:
- text: <code>homeworkStack</code>应该只包含4个元素。
testString: 'assert(homeworkStack.length === 4, "<code>homeworkStack</code> should only contain 4 elements.");'
- text: <code>homeworkStack</code>的最后一个元素应该是<code>"CS50"</code> 。
testString: 'assert(homeworkStack[3] === "CS50", "The last element in <code>homeworkStack</code> should be <code>"CS50"</code>.");'
- text: <code>homeworkStack</code>不应包含<code>"PSY44"</code> 。
testString: 'assert(homeworkStack.indexOf("PSY44") === -1, "<code>homeworkStack</code> should not contain <code>"PSY44"</code>.");'
- text: 不应更改<code>homeworkStack</code>的初始声明。
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 <code>homeworkStack</code> should not be changed.");'
Challenge Seed
var homeworkStack = ["BIO12","HIS80","MAT122","PSY44"];
// Only change code below this line
Solution
// solution required