fix(i18n): chinese test suite (#38220)
* fix: Chinese test suite Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working. * fix: ran script, updated testStrings and solutions
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
6a7a7e6d7d
commit
b3213fc892
@ -20,25 +20,25 @@ localeTitle: 嘘谁
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>booWho(true)</code>应该返回true。
|
||||
testString: 'assert.strictEqual(booWho(true), true, "<code>booWho(true)</code> should return true.");'
|
||||
testString: assert.strictEqual(booWho(true), true);
|
||||
- text: <code>booWho(false)</code>应该返回true。
|
||||
testString: 'assert.strictEqual(booWho(false), true, "<code>booWho(false)</code> should return true.");'
|
||||
testString: assert.strictEqual(booWho(false), true);
|
||||
- text: '<code>booWho([1, 2, 3])</code>应该返回false。'
|
||||
testString: 'assert.strictEqual(booWho([1, 2, 3]), false, "<code>booWho([1, 2, 3])</code> should return false.");'
|
||||
testString: assert.strictEqual(booWho([1, 2, 3]), false);
|
||||
- text: '<code>booWho([].slice)</code>应该返回false。'
|
||||
testString: 'assert.strictEqual(booWho([].slice), false, "<code>booWho([].slice)</code> should return false.");'
|
||||
testString: assert.strictEqual(booWho([].slice), false);
|
||||
- text: '<code>booWho({ "a": 1 })</code>应该返回false。'
|
||||
testString: 'assert.strictEqual(booWho({ "a": 1 }), false, "<code>booWho({ "a": 1 })</code> should return false.");'
|
||||
testString: 'assert.strictEqual(booWho({ "a": 1 }), false);'
|
||||
- text: <code>booWho(1)</code>应该返回false。
|
||||
testString: 'assert.strictEqual(booWho(1), false, "<code>booWho(1)</code> should return false.");'
|
||||
testString: assert.strictEqual(booWho(1), false);
|
||||
- text: <code>booWho(NaN)</code>应该返回false。
|
||||
testString: 'assert.strictEqual(booWho(NaN), false, "<code>booWho(NaN)</code> should return false.");'
|
||||
testString: assert.strictEqual(booWho(NaN), false);
|
||||
- text: <code>booWho("a")</code>应该返回false。
|
||||
testString: 'assert.strictEqual(booWho("a"), false, "<code>booWho("a")</code> should return false.");'
|
||||
testString: assert.strictEqual(booWho("a"), false);
|
||||
- text: <code>booWho("true")</code>应该返回false。
|
||||
testString: 'assert.strictEqual(booWho("true"), false, "<code>booWho("true")</code> should return false.");'
|
||||
testString: assert.strictEqual(booWho("true"), false);
|
||||
- text: <code>booWho("false")</code>应该返回false。
|
||||
testString: 'assert.strictEqual(booWho("false"), false, "<code>booWho("false")</code> should return false.");'
|
||||
testString: assert.strictEqual(booWho("false"), false);
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,19 +20,19 @@ localeTitle: 矮胖的猴子
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>chunkArrayInGroups(["a", "b", "c", "d"], 2)</code>应返回<code>[["a", "b"], ["c", "d"]]</code> 。'
|
||||
testString: 'assert.deepEqual(chunkArrayInGroups(["a", "b", "c", "d"], 2), [["a", "b"], ["c", "d"]], "<code>chunkArrayInGroups(["a", "b", "c", "d"], 2)</code> should return <code>[["a", "b"], ["c", "d"]]</code>.");'
|
||||
testString: assert.deepEqual(chunkArrayInGroups(["a", "b", "c", "d"], 2), [["a", "b"], ["c", "d"]]);
|
||||
- text: '<code>chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3)</code>应返回<code>[[0, 1, 2], [3, 4, 5]]</code> 。'
|
||||
testString: 'assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3), [[0, 1, 2], [3, 4, 5]], "<code>chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3)</code> should return <code>[[0, 1, 2], [3, 4, 5]]</code>.");'
|
||||
testString: assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3), [[0, 1, 2], [3, 4, 5]]);
|
||||
- text: '<code>chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2)</code>应返回<code>[[0, 1], [2, 3], [4, 5]]</code> 。'
|
||||
testString: 'assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2), [[0, 1], [2, 3], [4, 5]], "<code>chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2)</code> should return <code>[[0, 1], [2, 3], [4, 5]]</code>.");'
|
||||
testString: assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2), [[0, 1], [2, 3], [4, 5]]);
|
||||
- text: '<code>chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4)</code>应该返回<code>[[0, 1, 2, 3], [4, 5]]</code> 。'
|
||||
testString: 'assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4), [[0, 1, 2, 3], [4, 5]], "<code>chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4)</code> should return <code>[[0, 1, 2, 3], [4, 5]]</code>.");'
|
||||
testString: assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4), [[0, 1, 2, 3], [4, 5]]);
|
||||
- text: '<code>chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3)</code>应该返回<code>[[0, 1, 2], [3, 4, 5], [6]]</code> 。'
|
||||
testString: 'assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3), [[0, 1, 2], [3, 4, 5], [6]], "<code>chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3)</code> should return <code>[[0, 1, 2], [3, 4, 5], [6]]</code>.");'
|
||||
testString: assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3), [[0, 1, 2], [3, 4, 5], [6]]);
|
||||
- text: '<code>chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4)</code>应返回<code>[[0, 1, 2, 3], [4, 5, 6, 7], [8]]</code> <code>chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4)</code> <code>[[0, 1, 2, 3], [4, 5, 6, 7], [8]]</code> 。'
|
||||
testString: 'assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4), [[0, 1, 2, 3], [4, 5, 6, 7], [8]], "<code>chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4)</code> should return <code>[[0, 1, 2, 3], [4, 5, 6, 7], [8]]</code>.");'
|
||||
testString: assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4), [[0, 1, 2, 3], [4, 5, 6, 7], [8]]);
|
||||
- text: '<code>chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2)</code>应返回<code>[[0, 1], [2, 3], [4, 5], [6, 7], [8]]</code> 。'
|
||||
testString: 'assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2), [[0, 1], [2, 3], [4, 5], [6, 7], [8]], "<code>chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2)</code> should return <code>[[0, 1], [2, 3], [4, 5], [6, 7], [8]]</code>.");'
|
||||
testString: assert.deepEqual(chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2), [[0, 1], [2, 3], [4, 5], [6, 7], [8]]);
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,27 +20,27 @@ localeTitle: 确认结束
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>confirmEnding("Bastian", "n")</code>应该返回true。'
|
||||
testString: 'assert(confirmEnding("Bastian", "n") === true, "<code>confirmEnding("Bastian", "n")</code> should return true.");'
|
||||
testString: assert(confirmEnding("Bastian", "n") === true);
|
||||
- text: '<code>confirmEnding("Congratulation", "on")</code>应该返回true。'
|
||||
testString: 'assert(confirmEnding("Congratulation", "on") === true, "<code>confirmEnding("Congratulation", "on")</code> should return true.");'
|
||||
testString: assert(confirmEnding("Congratulation", "on") === true);
|
||||
- text: '<code>confirmEnding("Connor", "n")</code>应返回false。'
|
||||
testString: 'assert(confirmEnding("Connor", "n") === false, "<code>confirmEnding("Connor", "n")</code> should return false.");'
|
||||
testString: assert(confirmEnding("Connor", "n") === false);
|
||||
- text: '<code>confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification")</code>应该返回false。'
|
||||
testString: 'assert(confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification") === false, "<code>confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification")</code> should return false.");'
|
||||
testString: assert(confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification") === false);
|
||||
- text: '<code>confirmEnding("He has to give me a new name", "name")</code>应该返回true。'
|
||||
testString: 'assert(confirmEnding("He has to give me a new name", "name") === true, "<code>confirmEnding("He has to give me a new name", "name")</code> should return true.");'
|
||||
testString: assert(confirmEnding("He has to give me a new name", "name") === true);
|
||||
- text: '<code>confirmEnding("Open sesame", "same")</code>应该返回true。'
|
||||
testString: 'assert(confirmEnding("Open sesame", "same") === true, "<code>confirmEnding("Open sesame", "same")</code> should return true.");'
|
||||
testString: assert(confirmEnding("Open sesame", "same") === true);
|
||||
- text: '<code>confirmEnding("Open sesame", "pen")</code>应该返回false。'
|
||||
testString: 'assert(confirmEnding("Open sesame", "pen") === false, "<code>confirmEnding("Open sesame", "pen")</code> should return false.");'
|
||||
testString: assert(confirmEnding("Open sesame", "pen") === false);
|
||||
- text: '<code>confirmEnding("Open sesame", "game")</code>应该返回false。'
|
||||
testString: 'assert(confirmEnding("Open sesame", "game") === false, "<code>confirmEnding("Open sesame", "game")</code> should return false.");'
|
||||
testString: assert(confirmEnding("Open sesame", "game") === false);
|
||||
- text: '<code>confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain")</code>应该返回虚假。'
|
||||
testString: 'assert(confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain") === false, "<code>confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain")</code> should return false.");'
|
||||
testString: assert(confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain") === false);
|
||||
- text: '<code>confirmEnding("Abstraction", "action")</code>应该返回true。'
|
||||
testString: 'assert(confirmEnding("Abstraction", "action") === true, "<code>confirmEnding("Abstraction", "action")</code> should return true.");'
|
||||
testString: assert(confirmEnding("Abstraction", "action") === true);
|
||||
- text: 不要使用内置方法<code>.endsWith()</code>来解决挑战。
|
||||
testString: 'assert(!(/\.endsWith\(.*?\)\s*?;?/.test(code)) && !(/\["endsWith"\]/.test(code)), "Do not use the built-in method <code>.endsWith()</code> to solve the challenge.");'
|
||||
testString: assert(!(/\.endsWith\(.*?\)\s*?;?/.test(code)) && !(/\['endsWith'\]/.test(code)));
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,17 +20,17 @@ localeTitle: 将摄氏温度转换为华氏温度
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>convertToF(0)</code>应该返回一个数字
|
||||
testString: 'assert(typeof convertToF(0) === "number", "<code>convertToF(0)</code> should return a number");'
|
||||
testString: assert(typeof convertToF(0) === 'number');
|
||||
- text: <code>convertToF(-30)</code>应该返回值<code>-22</code>
|
||||
testString: 'assert(convertToF(-30) === -22, "<code>convertToF(-30)</code> should return a value of <code>-22</code>");'
|
||||
testString: assert(convertToF(-30) === -22);
|
||||
- text: <code>convertToF(-10)</code>应该返回值<code>14</code>
|
||||
testString: 'assert(convertToF(-10) === 14, "<code>convertToF(-10)</code> should return a value of <code>14</code>");'
|
||||
testString: assert(convertToF(-10) === 14);
|
||||
- text: <code>convertToF(0)</code>应返回值<code>32</code>
|
||||
testString: 'assert(convertToF(0) === 32, "<code>convertToF(0)</code> should return a value of <code>32</code>");'
|
||||
testString: assert(convertToF(0) === 32);
|
||||
- text: <code>convertToF(20)</code>应返回值<code>68</code>
|
||||
testString: 'assert(convertToF(20) === 68, "<code>convertToF(20)</code> should return a value of <code>68</code>");'
|
||||
testString: assert(convertToF(20) === 68);
|
||||
- text: <code>convertToF(30)</code>应返回值<code>86</code>
|
||||
testString: 'assert(convertToF(30) === 86, "<code>convertToF(30)</code> should return a value of <code>86</code>");'
|
||||
testString: assert(convertToF(30) === 86);
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,15 +20,15 @@ localeTitle: 对一个数字进行推理
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>factorialize(5)</code>应该返回一个数字。
|
||||
testString: 'assert(typeof factorialize(5) === "number", "<code>factorialize(5)</code> should return a number.");'
|
||||
testString: assert(typeof factorialize(5) === 'number');
|
||||
- text: <code>factorialize(5)</code>应该返回120。
|
||||
testString: 'assert(factorialize(5) === 120, "<code>factorialize(5)</code> should return 120.");'
|
||||
testString: assert(factorialize(5) === 120);
|
||||
- text: <code>factorialize(10)</code>应返回3628800。
|
||||
testString: 'assert(factorialize(10) === 3628800, "<code>factorialize(10)</code> should return 3628800.");'
|
||||
testString: assert(factorialize(10) === 3628800);
|
||||
- text: <code>factorialize(20)</code>应该返回2432902008176640000。
|
||||
testString: 'assert(factorialize(20) === 2432902008176640000, "<code>factorialize(20)</code> should return 2432902008176640000.");'
|
||||
testString: assert(factorialize(20) === 2432902008176640000);
|
||||
- text: <code>factorialize(0)</code>应该返回1。
|
||||
testString: 'assert(factorialize(0) === 1, "<code>factorialize(0)</code> should return 1.");'
|
||||
testString: assert(factorialize(0) === 1);
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,13 +20,13 @@ localeTitle: Falsy Bouncer
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>bouncer([7, "ate", "", false, 9])</code>应该返回<code>[7, "ate", 9]</code> 。'
|
||||
testString: 'assert.deepEqual(bouncer([7, "ate", "", false, 9]), [7, "ate", 9], "<code>bouncer([7, "ate", "", false, 9])</code> should return <code>[7, "ate", 9]</code>.");'
|
||||
testString: assert.deepEqual(bouncer([7, "ate", "", false, 9]), [7, "ate", 9]);
|
||||
- text: '<code>bouncer(["a", "b", "c"])</code>应返回<code>["a", "b", "c"]</code> 。'
|
||||
testString: 'assert.deepEqual(bouncer(["a", "b", "c"]), ["a", "b", "c"], "<code>bouncer(["a", "b", "c"])</code> should return <code>["a", "b", "c"]</code>.");'
|
||||
testString: assert.deepEqual(bouncer(["a", "b", "c"]), ["a", "b", "c"]);
|
||||
- text: '<code>bouncer([false, null, 0, NaN, undefined, ""])</code>应返回<code>[]</code> 。'
|
||||
testString: 'assert.deepEqual(bouncer([false, null, 0, NaN, undefined, ""]), [], "<code>bouncer([false, null, 0, NaN, undefined, ""])</code> should return <code>[]</code>.");'
|
||||
testString: assert.deepEqual(bouncer([false, null, 0, NaN, undefined, ""]), []);
|
||||
- text: '<code>bouncer([1, null, NaN, 2, undefined])</code>应该返回<code>[1, 2]</code> 。'
|
||||
testString: 'assert.deepEqual(bouncer([1, null, NaN, 2, undefined]), [1, 2], "<code>bouncer([1, null, NaN, 2, undefined])</code> should return <code>[1, 2]</code>.");'
|
||||
testString: assert.deepEqual(bouncer([null, NaN, 1, 2, undefined]), [1, 2]);
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,17 +20,17 @@ localeTitle: 找到字符串中最长的单词
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>findLongestWordLength("The quick brown fox jumped over the lazy dog")</code>应该返回一个数字。
|
||||
testString: 'assert(typeof findLongestWordLength("The quick brown fox jumped over the lazy dog") === "number", "<code>findLongestWordLength("The quick brown fox jumped over the lazy dog")</code> should return a number.");'
|
||||
testString: assert(typeof findLongestWordLength("The quick brown fox jumped over the lazy dog") === "number");
|
||||
- text: <code>findLongestWordLength("The quick brown fox jumped over the lazy dog")</code>应该返回6。
|
||||
testString: 'assert(findLongestWordLength("The quick brown fox jumped over the lazy dog") === 6, "<code>findLongestWordLength("The quick brown fox jumped over the lazy dog")</code> should return 6.");'
|
||||
testString: assert(findLongestWordLength("The quick brown fox jumped over the lazy dog") === 6);
|
||||
- text: <code>findLongestWordLength("May the force be with you")</code>应该返回5。
|
||||
testString: 'assert(findLongestWordLength("May the force be with you") === 5, "<code>findLongestWordLength("May the force be with you")</code> should return 5.");'
|
||||
testString: assert(findLongestWordLength("May the force be with you") === 5);
|
||||
- text: <code>findLongestWordLength("Google do a barrel roll")</code>应返回6。
|
||||
testString: 'assert(findLongestWordLength("Google do a barrel roll") === 6, "<code>findLongestWordLength("Google do a barrel roll")</code> should return 6.");'
|
||||
testString: assert(findLongestWordLength("Google do a barrel roll") === 6);
|
||||
- text: <code>findLongestWordLength("What is the average airspeed velocity of an unladen swallow")</code>应该返回8。
|
||||
testString: 'assert(findLongestWordLength("What is the average airspeed velocity of an unladen swallow") === 8, "<code>findLongestWordLength("What is the average airspeed velocity of an unladen swallow")</code> should return 8.");'
|
||||
testString: assert(findLongestWordLength("What is the average airspeed velocity of an unladen swallow") === 8);
|
||||
- text: <code>findLongestWordLength("What if we try a super-long word such as otorhinolaryngology")</code>应该返回19。
|
||||
testString: 'assert(findLongestWordLength("What if we try a super-long word such as otorhinolaryngology") === 19, "<code>findLongestWordLength("What if we try a super-long word such as otorhinolaryngology")</code> should return 19.");'
|
||||
testString: assert(findLongestWordLength("What if we try a super-long word such as otorhinolaryngology") === 19);
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,9 +20,9 @@ localeTitle: Finders Keepers
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>findElement([1, 3, 5, 8, 9, 10], function(num) { return num % 2 === 0; })</code>应该返回8。'
|
||||
testString: 'assert.strictEqual(findElement([1, 3, 5, 8, 9, 10], function(num) { return num % 2 === 0; }), 8, "<code>findElement([1, 3, 5, 8, 9, 10], function(num) { return num % 2 === 0; })</code> should return 8.");'
|
||||
testString: assert.strictEqual(findElement([1, 3, 5, 8, 9, 10], function(num) { return num % 2 === 0; }), 8);
|
||||
- text: '<code>findElement([1, 3, 5, 9], function(num) { return num % 2 === 0; })</code>应返回undefined。'
|
||||
testString: 'assert.strictEqual(findElement([1, 3, 5, 9], function(num) { return num % 2 === 0; }), undefined, "<code>findElement([1, 3, 5, 9], function(num) { return num % 2 === 0; })</code> should return undefined.");'
|
||||
testString: assert.strictEqual(findElement([1, 3, 5, 9], function(num) { return num % 2 === 0; }), undefined);
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,23 +20,23 @@ localeTitle: 突变
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>mutation(["hello", "hey"])</code>应该返回false。'
|
||||
testString: 'assert(mutation(["hello", "hey"]) === false, "<code>mutation(["hello", "hey"])</code> should return false.");'
|
||||
testString: assert(mutation(["hello", "hey"]) === false);
|
||||
- text: '<code>mutation(["hello", "Hello"])</code>应该返回true。'
|
||||
testString: 'assert(mutation(["hello", "Hello"]) === true, "<code>mutation(["hello", "Hello"])</code> should return true.");'
|
||||
testString: assert(mutation(["hello", "Hello"]) === true);
|
||||
- text: '<code>mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"])</code>应该返回true。'
|
||||
testString: 'assert(mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"]) === true, "<code>mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"])</code> should return true.");'
|
||||
testString: assert(mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"]) === true);
|
||||
- text: '<code>mutation(["Mary", "Army"])</code>应该返回true。'
|
||||
testString: 'assert(mutation(["Mary", "Army"]) === true, "<code>mutation(["Mary", "Army"])</code> should return true.");'
|
||||
testString: assert(mutation(["Mary", "Army"]) === true);
|
||||
- text: '<code>mutation(["Mary", "Aarmy"])</code>应该返回true。'
|
||||
testString: 'assert(mutation(["Mary", "Aarmy"]) === true, "<code>mutation(["Mary", "Aarmy"])</code> should return true.");'
|
||||
testString: assert(mutation(["Mary", "Aarmy"]) === true);
|
||||
- text: '<code>mutation(["Alien", "line"])</code>应该返回true。'
|
||||
testString: 'assert(mutation(["Alien", "line"]) === true, "<code>mutation(["Alien", "line"])</code> should return true.");'
|
||||
testString: assert(mutation(["Alien", "line"]) === true);
|
||||
- text: '<code>mutation(["floor", "for"])</code>应该返回true。'
|
||||
testString: 'assert(mutation(["floor", "for"]) === true, "<code>mutation(["floor", "for"])</code> should return true.");'
|
||||
testString: assert(mutation(["floor", "for"]) === true);
|
||||
- text: '<code>mutation(["hello", "neo"])</code>应该返回false。'
|
||||
testString: 'assert(mutation(["hello", "neo"]) === false, "<code>mutation(["hello", "neo"])</code> should return false.");'
|
||||
testString: assert(mutation(["hello", "neo"]) === false);
|
||||
- text: '<code>mutation(["voodoo", "no"])</code>应该返回false。'
|
||||
testString: 'assert(mutation(["voodoo", "no"]) === false, "<code>mutation(["voodoo", "no"])</code> should return false.");'
|
||||
testString: assert(mutation(["voodoo", "no"]) === false);
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,19 +20,19 @@ localeTitle: 重复一个字符串重复字符串
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>repeatStringNumTimes("*", 3)</code>应该返回<code>"***"</code> 。'
|
||||
testString: 'assert(repeatStringNumTimes("*", 3) === "***", "<code>repeatStringNumTimes("*", 3)</code> should return <code>"***"</code>.");'
|
||||
testString: assert(repeatStringNumTimes("*", 3) === "***");
|
||||
- text: '<code>repeatStringNumTimes("abc", 3)</code>应该返回<code>"abcabcabc"</code> 。'
|
||||
testString: 'assert(repeatStringNumTimes("abc", 3) === "abcabcabc", "<code>repeatStringNumTimes("abc", 3)</code> should return <code>"abcabcabc"</code>.");'
|
||||
testString: assert(repeatStringNumTimes("abc", 3) === "abcabcabc");
|
||||
- text: '<code>repeatStringNumTimes("abc", 4)</code>应返回<code>"abcabcabcabc"</code> 。'
|
||||
testString: 'assert(repeatStringNumTimes("abc", 4) === "abcabcabcabc", "<code>repeatStringNumTimes("abc", 4)</code> should return <code>"abcabcabcabc"</code>.");'
|
||||
testString: assert(repeatStringNumTimes("abc", 4) === "abcabcabcabc");
|
||||
- text: '<code>repeatStringNumTimes("abc", 1)</code>应该返回<code>"abc"</code> 。'
|
||||
testString: 'assert(repeatStringNumTimes("abc", 1) === "abc", "<code>repeatStringNumTimes("abc", 1)</code> should return <code>"abc"</code>.");'
|
||||
testString: assert(repeatStringNumTimes("abc", 1) === "abc");
|
||||
- text: '<code>repeatStringNumTimes("*", 8)</code>应该返回<code>"********"</code> 。'
|
||||
testString: 'assert(repeatStringNumTimes("*", 8) === "********", "<code>repeatStringNumTimes("*", 8)</code> should return <code>"********"</code>.");'
|
||||
testString: assert(repeatStringNumTimes("*", 8) === "********");
|
||||
- text: '<code>repeatStringNumTimes("abc", -2)</code>应返回<code>""</code> 。'
|
||||
testString: 'assert(repeatStringNumTimes("abc", -2) === "", "<code>repeatStringNumTimes("abc", -2)</code> should return <code>""</code>.");'
|
||||
testString: assert(repeatStringNumTimes("abc", -2) === "");
|
||||
- text: 不应使用内置的<code>repeat()</code>方法
|
||||
testString: 'assert(!/\.repeat/g.test(code), "The built-in <code>repeat()</code>-method should not be used");'
|
||||
testString: assert(!/\.repeat/g.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,13 +20,13 @@ localeTitle: 返回数组中的最大数字
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]])</code>应该返回一个数组。'
|
||||
testString: 'assert(largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]).constructor === Array, "<code>largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]])</code> should return an array.");'
|
||||
testString: assert(largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]).constructor === Array);
|
||||
- text: '<code>largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]])</code>应该返回<code>[27, 5, 39, 1001]</code> <code>largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]])</code> <code>[27, 5, 39, 1001]</code> 。'
|
||||
testString: 'assert.deepEqual(largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]]), [27, 5, 39, 1001], "<code>largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]])</code> should return <code>[27, 5, 39, 1001]</code>.");'
|
||||
testString: assert.deepEqual(largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]]), [27, 5, 39, 1001]);
|
||||
- text: '<code>largestOfFour([[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]])</code>应该返回<code>[9, 35, 97, 1000000]</code> <code>largestOfFour([[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]])</code> <code>[9, 35, 97, 1000000]</code> 。'
|
||||
testString: 'assert.deepEqual(largestOfFour([[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]]), [9, 35, 97, 1000000], "<code>largestOfFour([[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]])</code> should return <code>[9, 35, 97, 1000000]</code>.");'
|
||||
testString: assert.deepEqual(largestOfFour([[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]]), [9, 35, 97, 1000000]);
|
||||
- text: '<code>largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]])</code>应该返回<code>[25, 48, 21, -3]</code> 。'
|
||||
testString: 'assert.deepEqual(largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]), [25, 48, 21, -3], "<code>largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]])</code> should return <code>[25, 48, 21, -3]</code>.");'
|
||||
testString: assert.deepEqual(largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]]), [25, 48, 21, -3]);
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,13 +20,13 @@ localeTitle: 反转字符串
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>reverseString("hello")</code>应该返回一个字符串。
|
||||
testString: 'assert(typeof reverseString("hello") === "string", "<code>reverseString("hello")</code> should return a string.");'
|
||||
testString: assert(typeof reverseString("hello") === "string");
|
||||
- text: <code>reverseString("hello")</code>应该变成<code>"olleh"</code> 。
|
||||
testString: 'assert(reverseString("hello") === "olleh", "<code>reverseString("hello")</code> should become <code>"olleh"</code>.");'
|
||||
testString: assert(reverseString("hello") === "olleh");
|
||||
- text: <code>reverseString("Howdy")</code>应该变成<code>"ydwoH"</code> 。
|
||||
testString: 'assert(reverseString("Howdy") === "ydwoH", "<code>reverseString("Howdy")</code> should become <code>"ydwoH"</code>.");'
|
||||
testString: assert(reverseString("Howdy") === "ydwoH");
|
||||
- text: <code>reverseString("Greetings from Earth")</code>应返回<code>"htraE morf sgniteerG"</code> 。
|
||||
testString: 'assert(reverseString("Greetings from Earth") === "htraE morf sgniteerG", "<code>reverseString("Greetings from Earth")</code> should return <code>"htraE morf sgniteerG"</code>.");'
|
||||
testString: assert(reverseString("Greetings from Earth") === "htraE morf sgniteerG");
|
||||
|
||||
```
|
||||
|
||||
|
@ -21,17 +21,17 @@ localeTitle: 切片和拼接
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>frankenSplice([1, 2, 3], [4, 5], 1)</code>应该返回<code>[4, 1, 2, 3, 5]</code> <code>frankenSplice([1, 2, 3], [4, 5], 1)</code> <code>[4, 1, 2, 3, 5]</code> 。'
|
||||
testString: 'assert.deepEqual(frankenSplice([1, 2, 3], [4, 5], 1), [4, 1, 2, 3, 5], "<code>frankenSplice([1, 2, 3], [4, 5], 1)</code> should return <code>[4, 1, 2, 3, 5]</code>.");'
|
||||
testString: assert.deepEqual(frankenSplice([1, 2, 3], [4, 5], 1), [4, 1, 2, 3, 5]);
|
||||
- text: '<code>frankenSplice([1, 2], ["a", "b"], 1)</code>应返回<code>["a", 1, 2, "b"]</code> 。'
|
||||
testString: 'assert.deepEqual(frankenSplice(testArr1, testArr2, 1), ["a", 1, 2, "b"], "<code>frankenSplice([1, 2], ["a", "b"], 1)</code> should return <code>["a", 1, 2, "b"]</code>.");'
|
||||
testString: assert.deepEqual(frankenSplice(testArr1, testArr2, 1), ["a", 1, 2, "b"]);
|
||||
- text: '<code>frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2)</code>应该返回<code>["head", "shoulders", "claw", "tentacle", "knees", "toes"]</code> 。'
|
||||
testString: 'assert.deepEqual(frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2), ["head", "shoulders", "claw", "tentacle", "knees", "toes"], "<code>frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2)</code> should return <code>["head", "shoulders", "claw", "tentacle", "knees", "toes"]</code>.");'
|
||||
testString: assert.deepEqual(frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2), ["head", "shoulders", "claw", "tentacle", "knees", "toes"]);
|
||||
- text: 第一个数组中的所有元素都应按原始顺序添加到第二个数组中。
|
||||
testString: 'assert.deepEqual(frankenSplice([1, 2, 3, 4], [], 0), [1, 2, 3, 4], "All elements from the first array should be added to the second array in their original order.");'
|
||||
testString: assert.deepEqual(frankenSplice([1, 2, 3, 4], [], 0), [1, 2, 3, 4]);
|
||||
- text: 函数运行后,第一个数组应保持不变。
|
||||
testString: 'assert(testArr1[0] === 1 && testArr1[1] === 2, "The first array should remain the same after the function runs.");'
|
||||
testString: assert(testArr1[0] === 1 && testArr1[1] === 2);
|
||||
- text: 函数运行后,第二个数组应保持不变。
|
||||
testString: 'assert(testArr2[0] === "a" && testArr2[1] === "b", "The second array should remain the same after the function runs.");'
|
||||
testString: assert(testArr2[0] === "a" && testArr2[1] === "b");
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,13 +20,13 @@ localeTitle: 标题案例句子
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>titleCase("I'm a little tea pot")</code>应该返回一个字符串。'
|
||||
testString: 'assert(typeof titleCase("I"m a little tea pot") === "string", "<code>titleCase("I'm a little tea pot")</code> should return a string.");'
|
||||
testString: assert(typeof titleCase("I'm a little tea pot") === "string");
|
||||
- text: '<code>titleCase("I'm a little tea pot")</code>应该归还<code>I'm A Little Tea Pot</code> 。'
|
||||
testString: 'assert(titleCase("I"m a little tea pot") === "I"m A Little Tea Pot", "<code>titleCase("I'm a little tea pot")</code> should return <code>I'm A Little Tea Pot</code>.");'
|
||||
testString: assert(titleCase("I'm a little tea pot") === "I'm A Little Tea Pot");
|
||||
- text: <code>titleCase("sHoRt AnD sToUt")</code>应返回<code>Short And Stout</code> 。
|
||||
testString: 'assert(titleCase("sHoRt AnD sToUt") === "Short And Stout", "<code>titleCase("sHoRt AnD sToUt")</code> should return <code>Short And Stout</code>.");'
|
||||
testString: assert(titleCase("sHoRt AnD sToUt") === "Short And Stout");
|
||||
- text: <code>titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")</code> <code>Here Is My Handle Here Is My Spout</code> <code>titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")</code>应该回到<code>Here Is My Handle Here Is My Spout</code> 。
|
||||
testString: 'assert(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT") === "Here Is My Handle Here Is My Spout", "<code>titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")</code> should return <code>Here Is My Handle Here Is My Spout</code>.");'
|
||||
testString: assert(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT") === "Here Is My Handle Here Is My Spout");
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,17 +20,17 @@ localeTitle: 截断字符串
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>truncateString("A-tisket a-tasket A green and yellow basket", 8)</code>应该返回“A-tisket ......”。'
|
||||
testString: 'assert(truncateString("A-tisket a-tasket A green and yellow basket", 8) === "A-tisket...", "<code>truncateString("A-tisket a-tasket A green and yellow basket", 8)</code> should return "A-tisket...".");'
|
||||
testString: assert(truncateString("A-tisket a-tasket A green and yellow basket", 8) === "A-tisket...");
|
||||
- text: '<code>truncateString("Peter Piper picked a peck of pickled peppers", 11)</code>应该回归“Peter Piper ......”。'
|
||||
testString: 'assert(truncateString("Peter Piper picked a peck of pickled peppers", 11) === "Peter Piper...", "<code>truncateString("Peter Piper picked a peck of pickled peppers", 11)</code> should return "Peter Piper...".");'
|
||||
testString: assert(truncateString("Peter Piper picked a peck of pickled peppers", 11) === "Peter Piper...");
|
||||
- text: '<code>truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length)</code>应该返回“A-tisket a-tasket A green and yellow basket”。'
|
||||
testString: 'assert(truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length) === "A-tisket a-tasket A green and yellow basket", "<code>truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length)</code> should return "A-tisket a-tasket A green and yellow basket".");'
|
||||
testString: assert(truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length) === "A-tisket a-tasket A green and yellow basket");
|
||||
- text: '<code>truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length + 2)</code>应返回“A-tisket a-tasket A green and yellow basket”。'
|
||||
testString: 'assert(truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length + 2) === "A-tisket a-tasket A green and yellow basket", "<code>truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length + 2)</code> should return "A-tisket a-tasket A green and yellow basket".");'
|
||||
testString: assert(truncateString('A-tisket a-tasket A green and yellow basket', 'A-tisket a-tasket A green and yellow basket'.length + 2) === 'A-tisket a-tasket A green and yellow basket');
|
||||
- text: '<code>truncateString("A-", 1)</code>应返回“A ...”。'
|
||||
testString: 'assert(truncateString("A-", 1) === "A...", "<code>truncateString("A-", 1)</code> should return "A...".");'
|
||||
testString: assert(truncateString("A-", 1) === "A...");
|
||||
- text: '<code>truncateString("Absolutely Longer", 2)</code>应返回“Ab ...”。'
|
||||
testString: 'assert(truncateString("Absolutely Longer", 2) === "Ab...", "<code>truncateString("Absolutely Longer", 2)</code> should return "Ab...".");'
|
||||
testString: assert(truncateString("Absolutely Longer", 2) === "Ab...");
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,37 +20,37 @@ localeTitle: 我属于哪里?
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>getIndexToIns([10, 20, 30, 40, 50], 35)</code>应返回<code>3</code> 。'
|
||||
testString: 'assert(getIndexToIns([10, 20, 30, 40, 50], 35) === 3, "<code>getIndexToIns([10, 20, 30, 40, 50], 35)</code> should return <code>3</code>.");'
|
||||
testString: assert(getIndexToIns([10, 20, 30, 40, 50], 35) === 3);
|
||||
- text: '<code>getIndexToIns([10, 20, 30, 40, 50], 35)</code>应返回一个数字。'
|
||||
testString: 'assert(typeof(getIndexToIns([10, 20, 30, 40, 50], 35)) === "number", "<code>getIndexToIns([10, 20, 30, 40, 50], 35)</code> should return a number.");'
|
||||
testString: assert(typeof(getIndexToIns([10, 20, 30, 40, 50], 35)) === "number");
|
||||
- text: '<code>getIndexToIns([10, 20, 30, 40, 50], 30)</code>应该返回<code>2</code> 。'
|
||||
testString: 'assert(getIndexToIns([10, 20, 30, 40, 50], 30) === 2, "<code>getIndexToIns([10, 20, 30, 40, 50], 30)</code> should return <code>2</code>.");'
|
||||
testString: assert(getIndexToIns([10, 20, 30, 40, 50], 30) === 2);
|
||||
- text: '<code>getIndexToIns([10, 20, 30, 40, 50], 30)</code>应该返回一个数字。'
|
||||
testString: 'assert(typeof(getIndexToIns([10, 20, 30, 40, 50], 30)) === "number", "<code>getIndexToIns([10, 20, 30, 40, 50], 30)</code> should return a number.");'
|
||||
testString: assert(typeof(getIndexToIns([10, 20, 30, 40, 50], 30)) === "number");
|
||||
- text: '<code>getIndexToIns([40, 60], 50)</code>应返回<code>1</code> 。'
|
||||
testString: 'assert(getIndexToIns([40, 60], 50) === 1, "<code>getIndexToIns([40, 60], 50)</code> should return <code>1</code>.");'
|
||||
testString: assert(getIndexToIns([40, 60], 50) === 1);
|
||||
- text: '<code>getIndexToIns([40, 60], 50)</code>应返回一个数字。'
|
||||
testString: 'assert(typeof(getIndexToIns([40, 60], 50)) === "number", "<code>getIndexToIns([40, 60], 50)</code> should return a number.");'
|
||||
testString: assert(typeof(getIndexToIns([40, 60], 50)) === "number");
|
||||
- text: '<code>getIndexToIns([3, 10, 5], 3)</code>应该返回<code>0</code> 。'
|
||||
testString: 'assert(getIndexToIns([3, 10, 5], 3) === 0, "<code>getIndexToIns([3, 10, 5], 3)</code> should return <code>0</code>.");'
|
||||
testString: assert(getIndexToIns([3, 10, 5], 3) === 0);
|
||||
- text: '<code>getIndexToIns([3, 10, 5], 3)</code>应返回一个数字。'
|
||||
testString: 'assert(typeof(getIndexToIns([3, 10, 5], 3)) === "number", "<code>getIndexToIns([3, 10, 5], 3)</code> should return a number.");'
|
||||
testString: assert(typeof(getIndexToIns([3, 10, 5], 3)) === "number");
|
||||
- text: '<code>getIndexToIns([5, 3, 20, 3], 5)</code>应返回<code>2</code> 。'
|
||||
testString: 'assert(getIndexToIns([5, 3, 20, 3], 5) === 2, "<code>getIndexToIns([5, 3, 20, 3], 5)</code> should return <code>2</code>.");'
|
||||
testString: assert(getIndexToIns([5, 3, 20, 3], 5) === 2);
|
||||
- text: '<code>getIndexToIns([5, 3, 20, 3], 5)</code>应返回一个数字。'
|
||||
testString: 'assert(typeof(getIndexToIns([5, 3, 20, 3], 5)) === "number", "<code>getIndexToIns([5, 3, 20, 3], 5)</code> should return a number.");'
|
||||
testString: assert(typeof(getIndexToIns([5, 3, 20, 3], 5)) === "number");
|
||||
- text: '<code>getIndexToIns([2, 20, 10], 19)</code>应该返回<code>2</code> 。'
|
||||
testString: 'assert(getIndexToIns([2, 20, 10], 19) === 2, "<code>getIndexToIns([2, 20, 10], 19)</code> should return <code>2</code>.");'
|
||||
testString: assert(getIndexToIns([2, 20, 10], 19) === 2);
|
||||
- text: '<code>getIndexToIns([2, 20, 10], 19)</code>应返回一个数字。'
|
||||
testString: 'assert(typeof(getIndexToIns([2, 20, 10], 19)) === "number", "<code>getIndexToIns([2, 20, 10], 19)</code> should return a number.");'
|
||||
testString: assert(typeof(getIndexToIns([2, 20, 10], 19)) === "number");
|
||||
- text: '<code>getIndexToIns([2, 5, 10], 15)</code>应该返回<code>3</code> 。'
|
||||
testString: 'assert(getIndexToIns([2, 5, 10], 15) === 3, "<code>getIndexToIns([2, 5, 10], 15)</code> should return <code>3</code>.");'
|
||||
testString: assert(getIndexToIns([2, 5, 10], 15) === 3);
|
||||
- text: '<code>getIndexToIns([2, 5, 10], 15)</code>应返回一个数字。'
|
||||
testString: 'assert(typeof(getIndexToIns([2, 5, 10], 15)) === "number", "<code>getIndexToIns([2, 5, 10], 15)</code> should return a number.");'
|
||||
testString: assert(typeof(getIndexToIns([2, 5, 10], 15)) === "number");
|
||||
- text: '<code>getIndexToIns([], 1)</code>应该返回<code>0</code> 。'
|
||||
testString: 'assert(getIndexToIns([], 1) === 0, "<code>getIndexToIns([], 1)</code> should return <code>0</code>.");'
|
||||
testString: assert(getIndexToIns([], 1) === 0);
|
||||
- text: '<code>getIndexToIns([], 1)</code>应该返回一个数字。'
|
||||
testString: 'assert(typeof(getIndexToIns([], 1)) === "number", "<code>getIndexToIns([], 1)</code> should return a number.");'
|
||||
testString: assert(typeof(getIndexToIns([], 1)) === "number");
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,13 +18,13 @@ localeTitle: 使用括号表示法访问数组的内容
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>myArray[0]</code>等于<code>"a"</code>'
|
||||
testString: 'assert.strictEqual(myArray[0], "a", "<code>myArray[0]</code> is equal to <code>"a"</code>");'
|
||||
testString: assert.strictEqual(myArray[0], "a");
|
||||
- text: '<code>myArray[1]</code>不再设置为<code>"b"</code>'
|
||||
testString: 'assert.notStrictEqual(myArray[1], "b", "<code>myArray[1]</code> is no longer set to <code>"b"</code>");'
|
||||
testString: assert.notStrictEqual(myArray[1], "b");
|
||||
- text: '<code>myArray[2]</code>等于<code>"c"</code>'
|
||||
testString: 'assert.strictEqual(myArray[2], "c", "<code>myArray[2]</code> is equal to <code>"c"</code>");'
|
||||
testString: assert.strictEqual(myArray[2], "c");
|
||||
- text: '<code>myArray[3]</code>等于<code>"d"</code>'
|
||||
testString: 'assert.strictEqual(myArray[3], "d", "<code>myArray[3]</code> is equal to <code>"d"</code>");'
|
||||
testString: assert.strictEqual(myArray[3], "d");
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,15 +18,15 @@ localeTitle: 使用括号表示法访问属性名称
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>checkInventory</code>是一个函数
|
||||
testString: 'assert.strictEqual(typeof checkInventory, "function", "<code>checkInventory</code> is a function");'
|
||||
testString: assert.strictEqual(typeof checkInventory, 'function');
|
||||
- text: '<code>foods</code>对象应该只有以下键值对: <code>apples: 25</code> , <code>oranges: 32</code> , <code>plums: 28</code> , <code>bananas: 13</code> , <code>grapes: 35</code> , <code>strawberries: 27</code>'
|
||||
testString: 'assert.deepEqual(foods, {apples: 25, oranges: 32, plums: 28, bananas: 13, grapes: 35, strawberries: 27}, "The <code>foods</code> object should have only the following key-value pairs: <code>apples: 25</code>, <code>oranges: 32</code>, <code>plums: 28</code>, <code>bananas: 13</code>, <code>grapes: 35</code>, <code>strawberries: 27</code>");'
|
||||
testString: 'assert.deepEqual(foods, {apples: 25, oranges: 32, plums: 28, bananas: 13, grapes: 35, strawberries: 27});'
|
||||
- text: <code>checkInventory("apples")</code>应该返回<code>25</code>
|
||||
testString: 'assert.strictEqual(checkInventory("apples"), 25, "<code>checkInventory("apples")</code> should return <code>25</code>");'
|
||||
testString: assert.strictEqual(checkInventory('apples'), 25);
|
||||
- text: <code>checkInventory("bananas")</code>应该返回<code>13</code>
|
||||
testString: 'assert.strictEqual(checkInventory("bananas"), 13, "<code>checkInventory("bananas")</code> should return <code>13</code>");'
|
||||
testString: assert.strictEqual(checkInventory('bananas'), 13);
|
||||
- text: <code>checkInventory("strawberries")</code>应该返回<code>27</code>
|
||||
testString: 'assert.strictEqual(checkInventory("strawberries"), 27, "<code>checkInventory("strawberries")</code> should return <code>27</code>");'
|
||||
testString: assert.strictEqual(checkInventory('strawberries'), 27);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,11 +18,11 @@ localeTitle: 使用push()和unshift()将项添加到数组
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>mixedNumbers(["IV", 5, "six"])</code>现在应该返回<code>["I", 2, "three", "IV", 5, "six", 7, "VIII", 9]</code>'
|
||||
testString: 'assert.deepEqual(mixedNumbers(["IV", 5, "six"]), ["I", 2, "three", "IV", 5, "six", 7, "VIII", 9], "<code>mixedNumbers(["IV", 5, "six"])</code> should now return <code>["I", 2, "three", "IV", 5, "six", 7, "VIII", 9]</code>");'
|
||||
testString: assert.deepEqual(mixedNumbers(['IV', 5, 'six']), ['I', 2, 'three', 'IV', 5, 'six', 7, 'VIII', 9]);
|
||||
- text: <code>mixedNumbers</code>函数应该使用<code>push()</code>方法
|
||||
testString: 'assert.notStrictEqual(mixedNumbers.toString().search(/\.push\(/), -1, "The <code>mixedNumbers</code> function should utilize the <code>push()</code> method");'
|
||||
testString: assert(mixedNumbers.toString().match(/\.push/));
|
||||
- text: <code>mixedNumbers</code>函数应该使用<code>unshift()</code>方法
|
||||
testString: 'assert.notStrictEqual(mixedNumbers.toString().search(/\.unshift\(/), -1, "The <code>mixedNumbers</code> function should utilize the <code>unshift()</code> method");'
|
||||
testString: assert(mixedNumbers.toString().match(/\.unshift/));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,13 +18,13 @@ localeTitle: 使用splice()添加项目
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>htmlColorNames</code>应该返回<code>["DarkSalmon", "BlanchedAlmond", "LavenderBlush", "PaleTurqoise", "FireBrick"]</code>'
|
||||
testString: 'assert.deepEqual(htmlColorNames(["DarkGoldenRod", "WhiteSmoke", "LavenderBlush", "PaleTurqoise", "FireBrick"]), ["DarkSalmon", "BlanchedAlmond", "LavenderBlush", "PaleTurqoise", "FireBrick"], "<code>htmlColorNames</code> should return <code>["DarkSalmon", "BlanchedAlmond", "LavenderBlush", "PaleTurqoise", "FireBrick"]</code>");'
|
||||
testString: assert.deepEqual(htmlColorNames(['DarkGoldenRod', 'WhiteSmoke', 'LavenderBlush', 'PaleTurquoise', 'FireBrick']), ['DarkSalmon', 'BlanchedAlmond', 'LavenderBlush', 'PaleTurquoise', 'FireBrick']);
|
||||
- text: <code>htmlColorNames</code>函数应该使用<code>splice()</code>方法
|
||||
testString: 'assert(/.splice/.test(code), "The <code>htmlColorNames</code> function should utilize the <code>splice()</code> method");'
|
||||
testString: assert(/.splice/.test(code));
|
||||
- text: 你不应该使用<code>shift()</code>或<code>unshift()</code> 。
|
||||
testString: 'assert(!/shift|unshift/.test(code), "You should not use <code>shift()</code> or <code>unshift()</code>.");'
|
||||
testString: assert(!/shift|unshift/.test(code));
|
||||
- text: 您不应该使用数组括号表示法。
|
||||
testString: 'assert(!/\[\d\]\s*=/.test(code), "You should not use array bracket notation.");'
|
||||
testString: assert(!/\[\d\]\s*=/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,15 +18,15 @@ localeTitle: 将键值对添加到JavaScript对象
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>foods</code>是一个对象
|
||||
testString: 'assert(typeof foods === "object", "<code>foods</code> is an object");'
|
||||
testString: assert(typeof foods === 'object');
|
||||
- text: <code>foods</code>对象有一个值为<code>13</code>的关键<code>"bananas"</code>
|
||||
testString: 'assert(foods.bananas === 13, "The <code>foods</code> object has a key <code>"bananas"</code> with a value of <code>13</code>");'
|
||||
testString: assert(foods.bananas === 13);
|
||||
- text: <code>foods</code>对象有一个关键的<code>"grapes"</code> ,价值<code>35</code>
|
||||
testString: 'assert(foods.grapes === 35, "The <code>foods</code> object has a key <code>"grapes"</code> with a value of <code>35</code>");'
|
||||
testString: assert(foods.grapes === 35);
|
||||
- text: <code>foods</code>对象有一个关键的<code>"strawberries"</code> ,值为<code>27</code>
|
||||
testString: 'assert(foods.strawberries === 27, "The <code>foods</code> object has a key <code>"strawberries"</code> with a value of <code>27</code>");'
|
||||
testString: assert(foods.strawberries === 27);
|
||||
- text: 应使用点或括号表示法设置键值对
|
||||
testString: 'assert(code.search(/bananas:/) === -1 && code.search(/grapes:/) === -1 && code.search(/strawberries:/) === -1, "The key-value pairs should be set using dot or bracket notation");'
|
||||
testString: assert(code.search(/bananas:/) === -1 && code.search(/grapes:/) === -1 && code.search(/strawberries:/) === -1);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,15 +18,15 @@ localeTitle: 使用indexOf()检查元素是否存在
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>quickCheck(["squash", "onions", "shallots"], "mushrooms")</code>应该返回<code>false</code>'
|
||||
testString: 'assert.strictEqual(quickCheck(["squash", "onions", "shallots"], "mushrooms"), false, "<code>quickCheck(["squash", "onions", "shallots"], "mushrooms")</code> should return <code>false</code>");'
|
||||
testString: assert.strictEqual(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms'), false);
|
||||
- text: '<code>quickCheck(["squash", "onions", "shallots"], "onions")</code>应该返回<code>true</code>'
|
||||
testString: 'assert.strictEqual(quickCheck(["squash", "onions", "shallots"], "onions"), true, "<code>quickCheck(["squash", "onions", "shallots"], "onions")</code> should return <code>true</code>");'
|
||||
testString: assert.strictEqual(quickCheck(['onions', 'squash', 'shallots'], 'onions'), true);
|
||||
- text: '<code>quickCheck([3, 5, 9, 125, 45, 2], 125)</code>应该返回<code>true</code>'
|
||||
testString: 'assert.strictEqual(quickCheck([3, 5, 9, 125, 45, 2], 125), true, "<code>quickCheck([3, 5, 9, 125, 45, 2], 125)</code> should return <code>true</code>");'
|
||||
testString: assert.strictEqual(quickCheck([3, 5, 9, 125, 45, 2], 125), true);
|
||||
- text: '<code>quickCheck([true, false, false], undefined)</code>应返回<code>false</code>'
|
||||
testString: 'assert.strictEqual(quickCheck([true, false, false], undefined), false, "<code>quickCheck([true, false, false], undefined)</code> should return <code>false</code>");'
|
||||
testString: assert.strictEqual(quickCheck([true, false, false], undefined), false);
|
||||
- text: <code>quickCheck</code>函数应该使用<code>indexOf()</code>方法
|
||||
testString: 'assert.notStrictEqual(quickCheck.toString().search(/\.indexOf\(/), -1, "The <code>quickCheck</code> function should utilize the <code>indexOf()</code> method");'
|
||||
testString: assert.notStrictEqual(quickCheck.toString().search(/\.indexOf\(/), -1);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 将数组与Spread运算符组合在一起
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>spreadOut</code>应该返回<code>["learning", "to", "code", "is", "fun"]</code>'
|
||||
testString: 'assert.deepEqual(spreadOut(), ["learning", "to", "code", "is", "fun"], "<code>spreadOut</code> should return <code>["learning", "to", "code", "is", "fun"]</code>");'
|
||||
testString: assert.deepEqual(spreadOut(), ['learning', 'to', 'code', 'is', 'fun']);
|
||||
- text: <code>spreadOut</code>函数应该使用扩展语法
|
||||
testString: 'assert.notStrictEqual(spreadOut.toString().search(/[...]/), -1, "The <code>spreadOut</code> function should utilize spread syntax");'
|
||||
testString: assert.notStrictEqual(spreadOut.toString().search(/[...]/), -1);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,15 +18,15 @@ localeTitle: 使用Spread Operator复制数组
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>copyMachine([true, false, true], 2)</code>应返回<code>[[true, false, true], [true, false, true]]</code>'
|
||||
testString: 'assert.deepEqual(copyMachine([true, false, true], 2), [[true, false, true], [true, false, true]], "<code>copyMachine([true, false, true], 2)</code> should return <code>[[true, false, true], [true, false, true]]</code>");'
|
||||
testString: assert.deepEqual(copyMachine([true, false, true], 2), [[true, false, true], [true, false, true]]);
|
||||
- text: '<code>copyMachine([1, 2, 3], 5)</code>应返回<code>[[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]]</code>'
|
||||
testString: 'assert.deepEqual(copyMachine([1, 2, 3], 5), [[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]], "<code>copyMachine([1, 2, 3], 5)</code> should return <code>[[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]]</code>");'
|
||||
testString: assert.deepEqual(copyMachine([1, 2, 3], 5), [[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]]);
|
||||
- text: '<code>copyMachine([true, true, null], 1)</code>应该返回<code>[[true, true, null]]</code>'
|
||||
testString: 'assert.deepEqual(copyMachine([true, true, null], 1), [[true, true, null]], "<code>copyMachine([true, true, null], 1)</code> should return <code>[[true, true, null]]</code>");'
|
||||
testString: assert.deepEqual(copyMachine([true, true, null], 1), [[true, true, null]]);
|
||||
- text: '<code>copyMachine(["it works"], 3)</code>应该返回<code>[["it works"], ["it works"], ["it works"]]</code>'
|
||||
testString: 'assert.deepEqual(copyMachine(["it works"], 3), [["it works"], ["it works"], ["it works"]], "<code>copyMachine(["it works"], 3)</code> should return <code>[["it works"], ["it works"], ["it works"]]</code>");'
|
||||
testString: assert.deepEqual(copyMachine(['it works'], 3), [['it works'], ['it works'], ['it works']]);
|
||||
- text: <code>copyMachine</code>函数应该使用带有数组<code>arr</code>的<code>spread operator</code>
|
||||
testString: 'assert.notStrictEqual(copyMachine.toString().indexOf(".concat(_toConsumableArray(arr))"), -1, "The <code>copyMachine</code> function should utilize the <code>spread operator</code> with array <code>arr</code>");'
|
||||
testString: assert(removeJSComments(code).match(/\.\.\.arr/));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 使用slice()复制数组项
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>forecast</code>应该返回<code>["warm", "sunny"]</code>'
|
||||
testString: 'assert.deepEqual(forecast(["cold", "rainy", "warm", "sunny", "cool", "thunderstorms"]), ["warm", "sunny"], "<code>forecast</code> should return <code>["warm", "sunny"]");'
|
||||
testString: assert.deepEqual(forecast(['cold', 'rainy', 'warm', 'sunny', 'cool', 'thunderstorms']), ['warm', 'sunny']);
|
||||
- text: <code>forecast</code>函数应该使用<code>slice()</code>方法
|
||||
testString: 'assert(/\.slice\(/.test(code), "The <code>forecast</code> function should utilize the <code>slice()</code> method");'
|
||||
testString: assert(/\.slice\(/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,15 +18,15 @@ localeTitle: 创建复杂的多维数组
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myNestedArray</code>应仅包含数字,布尔值和字符串作为数据元素
|
||||
testString: 'assert.strictEqual((function(arr) { let flattened = (function flatten(arr) { const flat = [].concat(...arr); return flat.some (Array.isArray) ? flatten(flat) : flat; })(arr); for (let i = 0; i < flattened.length; i++) { if ( typeof flattened[i] !== "number" && typeof flattened[i] !== "string" && typeof flattened[i] !== "boolean") { return false } } return true })(myNestedArray), true, "<code>myNestedArray</code> should contain only numbers, booleans, and strings as data elements");'
|
||||
testString: 'assert.strictEqual((function(arr) { let flattened = (function flatten(arr) { const flat = [].concat(...arr); return flat.some (Array.isArray) ? flatten(flat) : flat; })(arr); for (let i = 0; i < flattened.length; i++) { if ( typeof flattened[i] !== ''number'' && typeof flattened[i] !== ''string'' && typeof flattened[i] !== ''boolean'') { return false } } return true })(myNestedArray), true);'
|
||||
- text: <code>myNestedArray</code>应该有5个级别的深度
|
||||
testString: 'assert.strictEqual((function(arr) {let depth = 0;function arrayDepth(array, i, d) { if (Array.isArray(array[i])) { arrayDepth(array[i], 0, d + 1);} else { depth = (d > depth) ? d : depth;}if (i < array.length) { arrayDepth(array, i + 1, d);} }arrayDepth(arr, 0, 0);return depth;})(myNestedArray), 4, "<code>myNestedArray</code> should have exactly 5 levels of depth");'
|
||||
testString: 'assert.strictEqual((function(arr) {let depth = 0;function arrayDepth(array, i, d) { if (Array.isArray(array[i])) { arrayDepth(array[i], 0, d + 1);} else { depth = (d > depth) ? d : depth;}if (i < array.length) { arrayDepth(array, i + 1, d);} }arrayDepth(arr, 0, 0);return depth;})(myNestedArray), 4);'
|
||||
- text: <code>myNestedArray</code>应该在嵌套3级深度的数组中恰好包含一个字符串<code>"deep"</code>
|
||||
testString: 'assert((function howDeep(array, target, depth = 0) {return array.reduce((combined, current) => {if (Array.isArray(current)) { return combined.concat(howDeep(current, target, depth + 1));} else if (current === target) { return combined.concat(depth);} else { return combined;}}, []);})(myNestedArray, "deep").length === 1 && (function howDeep(array, target, depth = 0) {return array.reduce((combined, current) => {if (Array.isArray(current)) { return combined.concat(howDeep(current, target, depth + 1));} else if (current === target) { return combined.concat(depth);} else { return combined;}}, []);})(myNestedArray, "deep")[0] === 2, "<code>myNestedArray</code> should contain exactly one occurrence of the string <code>"deep"</code> on an array nested 3 levels deep");'
|
||||
testString: assert((function howDeep(array, target, depth = 0) {return array.reduce((combined, current) => {if (Array.isArray(current)) { return combined.concat(howDeep(current, target, depth + 1));} else if (current === target) { return combined.concat(depth);} else { return combined;}}, []);})(myNestedArray, 'deep').length === 1 && (function howDeep(array, target, depth = 0) {return array.reduce((combined, current) => {if (Array.isArray(current)) { return combined.concat(howDeep(current, target, depth + 1));} else if (current === target) { return combined.concat(depth);} else { return combined;}}, []);})(myNestedArray, 'deep')[0] === 2);
|
||||
- text: <code>myNestedArray</code>应该在嵌套4级深度的数组中恰好包含一个字符串<code>"deeper"</code> deep”
|
||||
testString: 'assert((function howDeep(array, target, depth = 0) {return array.reduce((combined, current) => {if (Array.isArray(current)) { return combined.concat(howDeep(current, target, depth + 1));} else if (current === target) { return combined.concat(depth);} else { return combined;}}, []);})(myNestedArray, "deeper").length === 1 && (function howDeep(array, target, depth = 0) {return array.reduce((combined, current) => {if (Array.isArray(current)) { return combined.concat(howDeep(current, target, depth + 1));} else if (current === target) { return combined.concat(depth);} else { return combined;}}, []);})(myNestedArray, "deeper")[0] === 3, "<code>myNestedArray</code> should contain exactly one occurrence of the string <code>"deeper"</code> on an array nested 4 levels deep");'
|
||||
testString: assert((function howDeep(array, target, depth = 0) {return array.reduce((combined, current) => {if (Array.isArray(current)) { return combined.concat(howDeep(current, target, depth + 1));} else if (current === target) { return combined.concat(depth);} else { return combined;}}, []);})(myNestedArray, 'deeper').length === 1 && (function howDeep(array, target, depth = 0) {return array.reduce((combined, current) => {if (Array.isArray(current)) { return combined.concat(howDeep(current, target, depth + 1));} else if (current === target) { return combined.concat(depth);} else { return combined;}}, []);})(myNestedArray, 'deeper')[0] === 3);
|
||||
- text: <code>myNestedArray</code>应该在嵌套5级深度的数组中恰好包含一个字符串<code>"deepest"</code> <code>myNestedArray</code> <code>"deepest"</code>
|
||||
testString: 'assert((function howDeep(array, target, depth = 0) {return array.reduce((combined, current) => {if (Array.isArray(current)) { return combined.concat(howDeep(current, target, depth + 1));} else if (current === target) { return combined.concat(depth);} else { return combined;}}, []);})(myNestedArray, "deepest").length === 1 && (function howDeep(array, target, depth = 0) {return array.reduce((combined, current) => {if (Array.isArray(current)) { return combined.concat(howDeep(current, target, depth + 1));} else if (current === target) { return combined.concat(depth);} else { return combined;}}, []);})(myNestedArray, "deepest")[0] === 4, "<code>myNestedArray</code> should contain exactly one occurrence of the string <code>"deepest"</code> on an array nested 5 levels deep");'
|
||||
testString: assert((function howDeep(array, target, depth = 0) {return array.reduce((combined, current) => {if (Array.isArray(current)) { return combined.concat(howDeep(current, target, depth + 1));} else if (current === target) { return combined.concat(depth);} else { return combined;}}, []);})(myNestedArray, 'deepest').length === 1 && (function howDeep(array, target, depth = 0) {return array.reduce((combined, current) => {if (Array.isArray(current)) { return combined.concat(howDeep(current, target, depth + 1));} else if (current === target) { return combined.concat(depth);} else { return combined;}}, []);})(myNestedArray, 'deepest')[0] === 4);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 使用Object.keys()生成所有对象键的数组
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>users</code>对象仅包含<code>Alan</code> , <code>Jeff</code> , <code>Sarah</code>和<code>Ryan</code>
|
||||
testString: 'assert("Alan" in users && "Jeff" in users && "Sarah" in users && "Ryan" in users && Object.keys(users).length === 4, "The <code>users</code> object only contains the keys <code>Alan</code>, <code>Jeff</code>, <code>Sarah</code>, and <code>Ryan</code>");'
|
||||
testString: assert('Alan' in users && 'Jeff' in users && 'Sarah' in users && 'Ryan' in users && Object.keys(users).length === 4);
|
||||
- text: <code>getArrayOfUsers</code>函数返回一个数组,其中包含<code>users</code>对象中的所有键
|
||||
testString: 'assert((function() { users.Sam = {}; users.Lewis = {}; let R = getArrayOfUsers(users); return (R.indexOf("Alan") !== -1 && R.indexOf("Jeff") !== -1 && R.indexOf("Sarah") !== -1 && R.indexOf("Ryan") !== -1 && R.indexOf("Sam") !== -1 && R.indexOf("Lewis") !== -1); })() === true, "The <code>getArrayOfUsers</code> function returns an array which contains all the keys in the <code>users</code> object");'
|
||||
testString: assert((function() { users.Sam = {}; users.Lewis = {}; let R = getArrayOfUsers(users); return (R.indexOf('Alan') !== -1 && R.indexOf('Jeff') !== -1 && R.indexOf('Sarah') !== -1 && R.indexOf('Ryan') !== -1 && R.indexOf('Sam') !== -1 && R.indexOf('Lewis') !== -1); })() === true);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,15 +18,15 @@ localeTitle: 使用for循环遍历所有数组的项目
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>filteredArray([[10, 8, 3], [14, 6, 23], [3, 18, 6]], 18)</code>应该返回<code>[ [10, 8, 3], [14, 6, 23] ]</code>'
|
||||
testString: 'assert.deepEqual(filteredArray([ [10, 8, 3], [14, 6, 23], [3, 18, 6] ], 18), [[10, 8, 3], [14, 6, 23]], "<code>filteredArray([[10, 8, 3], [14, 6, 23], [3, 18, 6]], 18)</code> should return <code>[ [10, 8, 3], [14, 6, 23] ]</code>");'
|
||||
testString: assert.deepEqual(filteredArray([ [10, 8, 3], [14, 6, 23], [3, 18, 6] ], 18), [[10, 8, 3], [14, 6, 23]]);
|
||||
- text: '<code>filteredArray([ ["trumpets", 2], ["flutes", 4], ["saxophones", 2] ], 2)</code>应返回<code>[ ["flutes", 4] ]</code>'
|
||||
testString: 'assert.deepEqual(filteredArray([ ["trumpets", 2], ["flutes", 4], ["saxophones", 2] ], 2), [["flutes", 4]], "<code>filteredArray([ ["trumpets", 2], ["flutes", 4], ["saxophones", 2] ], 2)</code> should return <code>[ ["flutes", 4] ]</code>");'
|
||||
testString: assert.deepEqual(filteredArray([ ['trumpets', 2], ['flutes', 4], ['saxophones', 2] ], 2), [['flutes', 4]]);
|
||||
- text: '<code>filteredArray([ ["amy", "beth", "sam"], ["dave", "sean", "peter"] ], "peter")</code>应该返回<code>[ ["amy", "beth", "sam"] ]</code>'
|
||||
testString: 'assert.deepEqual(filteredArray([["amy", "beth", "sam"], ["dave", "sean", "peter"]], "peter"), [["amy", "beth", "sam"]], "<code>filteredArray([ ["amy", "beth", "sam"], ["dave", "sean", "peter"] ], "peter")</code> should return <code>[ ["amy", "beth", "sam"] ]</code>");'
|
||||
testString: assert.deepEqual(filteredArray([['amy', 'beth', 'sam'], ['dave', 'sean', 'peter']], 'peter'), [['amy', 'beth', 'sam']]);
|
||||
- text: '<code>filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3)</code>应该返回<code>[ ]</code>'
|
||||
testString: 'assert.deepEqual(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3), [], "<code>filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3)</code> should return <code>[ ]</code>");'
|
||||
testString: assert.deepEqual(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3), []);
|
||||
- text: <code>filteredArray</code>函数应该使用<code>for</code>循环
|
||||
testString: 'assert.notStrictEqual(filteredArray.toString().search(/for/), -1, "The <code>filteredArray</code> function should utilize a <code>for</code> loop");'
|
||||
testString: assert.notStrictEqual(filteredArray.toString().search(/for/), -1);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,11 +18,11 @@ localeTitle: 修改存储在对象中的数组
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>user</code>对象具有<code>name</code> , <code>age</code>和<code>data</code>键
|
||||
testString: 'assert("name" in user && "age" in user && "data" in user, "The <code>user</code> object has <code>name</code>, <code>age</code>, and <code>data</code> keys");'
|
||||
testString: assert('name' in user && 'age' in user && 'data' in user);
|
||||
- text: <code>addFriend</code>函数接受<code>user</code>对象和<code>friend</code>字符串作为参数,并将朋友添加到<code>user</code>对象中的<code>friends</code>数组
|
||||
testString: 'assert((function() { let L1 = user.data.friends.length; addFriend(user, "Sean"); let L2 = user.data.friends.length; return (L2 === L1 + 1); })(), "The <code>addFriend</code> function accepts a <code>user</code> object and a <code>friend</code> string as arguments and adds the friend to the array of <code>friends</code> in the <code>user</code> object");'
|
||||
testString: assert((function() { let L1 = user.data.friends.length; addFriend(user, 'Sean'); let L2 = user.data.friends.length; return (L2 === L1 + 1); })());
|
||||
- text: '<code>addFriend(user, "Pete")</code>应该返回<code>["Sam", "Kira", "Tomo", "Pete"]</code>'
|
||||
testString: 'assert.deepEqual((function() { delete user.data.friends; user.data.friends = ["Sam", "Kira", "Tomo"]; return addFriend(user, "Pete") })(), ["Sam", "Kira", "Tomo", "Pete"], "<code>addFriend(user, "Pete")</code> should return <code>["Sam", "Kira", "Tomo", "Pete"]</code>");'
|
||||
testString: assert.deepEqual((function() { delete user.data.friends; user.data.friends = ['Sam', 'Kira', 'Tomo']; return addFriend(user, 'Pete') })(), ['Sam', 'Kira', 'Tomo', 'Pete']);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,13 +18,13 @@ localeTitle: 修改嵌套在对象中的对象
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>userActivity</code>具有<code>id</code> , <code>date</code>和<code>data</code>属性
|
||||
testString: 'assert("id" in userActivity && "date" in userActivity && "data" in userActivity, "<code>userActivity</code> has <code>id</code>, <code>date</code> and <code>data</code> properties");'
|
||||
testString: assert('id' in userActivity && 'date' in userActivity && 'data' in userActivity);
|
||||
- text: <code>userActivity</code>具有设置为具有密钥<code>totalUsers</code>和<code>online</code>的对象的<code>data</code>密钥
|
||||
testString: 'assert("totalUsers" in userActivity.data && "online" in userActivity.data, "<code>userActivity</code> has a <code>data</code> key set to an object with keys <code>totalUsers</code> and <code>online</code>");'
|
||||
testString: assert('totalUsers' in userActivity.data && 'online' in userActivity.data);
|
||||
- text: 嵌套在<code>userActivity</code> <code>data</code>键中的<code>online</code>属性应设置为<code>45</code>
|
||||
testString: 'assert(userActivity.data.online === 45, "The <code>online</code> property nested in the <code>data</code> key of <code>userActivity</code> should be set to <code>45</code>");'
|
||||
testString: assert(userActivity.data.online === 45);
|
||||
- text: <code>online</code>属性使用点或括号表示法设置
|
||||
testString: 'assert.strictEqual(code.search(/online: 45/), -1, "The <code>online</code> property is set using dot or bracket notation");'
|
||||
testString: 'assert.strictEqual(code.search(/online: 45/), -1);'
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,11 +18,11 @@ localeTitle: 使用pop()和shift()从数组中删除项
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>popShift(["challenge", "is", "not", "complete"])</code>应返回<code>["challenge", "complete"]</code>'
|
||||
testString: 'assert.deepEqual(popShift(["challenge", "is", "not", "complete"]), ["challenge", "complete"], "<code>popShift(["challenge", "is", "not", "complete"])</code> should return <code>["challenge", "complete"]</code>");'
|
||||
testString: assert.deepEqual(popShift(['challenge', 'is', 'not', 'complete']), ["challenge", "complete"]);
|
||||
- text: <code>popShift</code>函数应该使用<code>pop()</code>方法
|
||||
testString: 'assert.notStrictEqual(popShift.toString().search(/\.pop\(/), -1, "The <code>popShift</code> function should utilize the <code>pop()</code> method");'
|
||||
testString: assert.notStrictEqual(popShift.toString().search(/\.pop\(/), -1);
|
||||
- text: <code>popShift</code>函数应该使用<code>shift()</code>方法
|
||||
testString: 'assert.notStrictEqual(popShift.toString().search(/\.shift\(/), -1, "The <code>popShift</code> function should utilize the <code>shift()</code> method");'
|
||||
testString: assert.notStrictEqual(popShift.toString().search(/\.shift\(/), -1);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,15 +18,15 @@ localeTitle: 使用数组存储数据集合
|
||||
```yml
|
||||
tests:
|
||||
- text: yourArray是一个数组
|
||||
testString: 'assert.strictEqual(Array.isArray(yourArray), true, "yourArray is an array");'
|
||||
testString: assert.strictEqual(Array.isArray(yourArray), true);
|
||||
- text: <code>yourArray</code>至少有5个元素
|
||||
testString: 'assert.isAtLeast(yourArray.length, 5, "<code>yourArray</code> is at least 5 elements long");'
|
||||
testString: assert.isAtLeast(yourArray.length, 5);
|
||||
- text: <code>yourArray</code>至少包含一个<code>boolean</code>
|
||||
testString: 'assert(yourArray.filter( el => typeof el === "boolean").length >= 1, "<code>yourArray</code> contains at least one <code>boolean</code>");'
|
||||
testString: assert(yourArray.filter( el => typeof el === 'boolean').length >= 1);
|
||||
- text: <code>yourArray</code>至少包含一个<code>number</code>
|
||||
testString: 'assert(yourArray.filter( el => typeof el === "number").length >= 1, "<code>yourArray</code> contains at least one <code>number</code>");'
|
||||
testString: assert(yourArray.filter( el => typeof el === 'number').length >= 1);
|
||||
- text: <code>yourArray</code>至少包含一个<code>string</code>
|
||||
testString: 'assert(yourArray.filter( el => typeof el === "string").length >= 1, "<code>yourArray</code> contains at least one <code>string</code>");'
|
||||
testString: assert(yourArray.filter( el => typeof el === 'string').length >= 1);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 使用删除关键字删除对象属性
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>foods</code>对象只有三个键: <code>apples</code> , <code>grapes</code>和<code>bananas</code>
|
||||
testString: 'assert(!foods.hasOwnProperty("oranges") && !foods.hasOwnProperty("plums") && !foods.hasOwnProperty("strawberries") && Object.keys(foods).length === 3, "The <code>foods</code> object only has three keys: <code>apples</code>, <code>grapes</code>, and <code>bananas</code>");'
|
||||
testString: 'assert(!foods.hasOwnProperty(''oranges'') && !foods.hasOwnProperty(''plums'') && !foods.hasOwnProperty(''strawberries'') && Object.keys(foods).length === 3);'
|
||||
- text: 使用<code>delete</code> <code>oranges</code> , <code>plums</code>和<code>strawberries</code>键
|
||||
testString: 'assert(code.search(/oranges:/) !== -1 && code.search(/plums:/) !== -1 && code.search(/strawberries:/) !== -1, "The <code>oranges</code>, <code>plums</code>, and <code>strawberries</code> keys are removed using <code>delete</code>");'
|
||||
testString: assert(code.search(/oranges:/) !== -1 && code.search(/plums:/) !== -1 && code.search(/strawberries:/) !== -1);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 使用索引访问数组数据
|
||||
```yml
|
||||
tests:
|
||||
- text: 变量<code>myData</code>应该等于<code>myArray</code>的第一个值。
|
||||
testString: 'assert((function(){if(typeof myArray !== "undefined" && typeof myData !== "undefined" && myArray[0] === myData){return true;}else{return false;}})(), "The variable <code>myData</code> should equal the first value of <code>myArray</code>.");'
|
||||
testString: assert((function(){if(typeof myArray !== 'undefined' && typeof myData !== 'undefined' && myArray[0] === myData){return true;}else{return false;}})());
|
||||
- text: 应使用括号表示法访问变量<code>myArray</code>的数据。
|
||||
testString: 'assert((function(){if(code.match(/\s*=\s*myArray\[0\]/g)){return true;}else{return false;}})(), "The data in variable <code>myArray</code> should be accessed using bracket notation.");'
|
||||
testString: assert((function(){if(code.match(/\s*=\s*myArray\[0\]/g)){return true;}else{return false;}})());
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 访问带索引的多维数组
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myData</code>应该等于<code>8</code> 。
|
||||
testString: 'assert(myData === 8, "<code>myData</code> should be equal to <code>8</code>.");'
|
||||
testString: assert(myData === 8);
|
||||
- text: 您应该使用括号表示法从<code>myArray</code>读取正确的值。
|
||||
testString: 'assert(/myArray\[2\]\[1\]/g.test(code) && !/myData\s*=\s*(?:.*[-+*/%]|\d)/g.test(code), "You should be using bracket notation to read the correct value from <code>myArray</code>.");'
|
||||
testString: assert(/myData=myArray\[2\]\[1\]/.test(code.replace(/\s/g, '')));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 访问嵌套数组
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>secondTree</code>应该等于“松树”
|
||||
testString: 'assert(secondTree === "pine", "<code>secondTree</code> should equal "pine"");'
|
||||
testString: assert(secondTree === "pine");
|
||||
- text: 使用点和括号表示法访问<code>myPlants</code>
|
||||
testString: 'assert(/=\s*myPlants\[1\].list\[1\]/.test(code), "Use dot and bracket notation to access <code>myPlants</code>");'
|
||||
testString: assert(/=\s*myPlants\[1\].list\[1\]/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 访问嵌套对象
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>gloveBoxContents</code>应该等于“地图”
|
||||
testString: 'assert(gloveBoxContents === "maps", "<code>gloveBoxContents</code> should equal "maps"");'
|
||||
testString: assert(gloveBoxContents === "maps");
|
||||
- text: 使用点和括号表示法访问<code>myStorage</code>
|
||||
testString: 'assert(/=\s*myStorage\.car\.inside\[\s*("|")glove box\1\s*\]/g.test(code), "Use dot and bracket notation to access <code>myStorage</code>");'
|
||||
testString: assert(/=\s*myStorage\.car\.inside\[\s*("|')glove box\1\s*\]/g.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,15 +18,15 @@ localeTitle: 使用括号表示法访问对象属性
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>entreeValue</code>应该是一个字符串
|
||||
testString: 'assert(typeof entreeValue === "string" , "<code>entreeValue</code> should be a string");'
|
||||
testString: assert(typeof entreeValue === 'string' );
|
||||
- text: <code>entreeValue</code>的值应该是<code>"hamburger"</code>
|
||||
testString: 'assert(entreeValue === "hamburger" , "The value of <code>entreeValue</code> should be <code>"hamburger"</code>");'
|
||||
testString: assert(entreeValue === 'hamburger' );
|
||||
- text: <code>drinkValue</code>应该是一个字符串
|
||||
testString: 'assert(typeof drinkValue === "string" , "<code>drinkValue</code> should be a string");'
|
||||
testString: assert(typeof drinkValue === 'string' );
|
||||
- text: <code>drinkValue</code>的值应该是<code>"water"</code>
|
||||
testString: 'assert(drinkValue === "water" , "The value of <code>drinkValue</code> should be <code>"water"</code>");'
|
||||
testString: assert(drinkValue === 'water' );
|
||||
- text: 您应该使用括号表示法两次
|
||||
testString: 'assert(code.match(/testObj\s*?\[("|")[^""]+\1\]/g).length > 1, "You should use bracket notation twice");'
|
||||
testString: assert(code.match(/testObj\s*?\[('|")[^'"]+\1\]/g).length > 1);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,15 +18,15 @@ localeTitle: 使用点表示法访问对象属性
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>hatValue</code>应该是一个字符串
|
||||
testString: 'assert(typeof hatValue === "string" , "<code>hatValue</code> should be a string");'
|
||||
testString: assert(typeof hatValue === 'string' );
|
||||
- text: <code>hatValue</code>的值应该是<code>"ballcap"</code>
|
||||
testString: 'assert(hatValue === "ballcap" , "The value of <code>hatValue</code> should be <code>"ballcap"</code>");'
|
||||
testString: assert(hatValue === 'ballcap' );
|
||||
- text: <code>shirtValue</code>应该是一个字符串
|
||||
testString: 'assert(typeof shirtValue === "string" , "<code>shirtValue</code> should be a string");'
|
||||
testString: assert(typeof shirtValue === 'string' );
|
||||
- text: <code>shirtValue</code>的值应该是<code>"jersey"</code>
|
||||
testString: 'assert(shirtValue === "jersey" , "The value of <code>shirtValue</code> should be <code>"jersey"</code>");'
|
||||
testString: assert(shirtValue === 'jersey' );
|
||||
- text: 你应该使用点符号两次
|
||||
testString: 'assert(code.match(/testObj\.\w+/g).length > 1, "You should use dot notation twice");'
|
||||
testString: assert(code.match(/testObj\.\w+/g).length > 1);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,17 +18,17 @@ localeTitle: 使用变量访问对象属性
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>playerNumber</code>应该是一个数字
|
||||
testString: 'assert(typeof playerNumber === "number", "<code>playerNumber</code> should be a number");'
|
||||
testString: assert(typeof playerNumber === 'number');
|
||||
- text: 变量<code>player</code>应该是一个字符串
|
||||
testString: 'assert(typeof player === "string", "The variable <code>player</code> should be a string");'
|
||||
testString: assert(typeof player === 'string');
|
||||
- text: <code>player</code>的价值应该是“蒙大拿”
|
||||
testString: 'assert(player === "Montana", "The value of <code>player</code> should be "Montana"");'
|
||||
testString: assert(player === 'Montana');
|
||||
- text: 您应该使用括号表示法来访问<code>testObj</code>
|
||||
testString: 'assert(/testObj\s*?\[.*?\]/.test(code),"You should use bracket notation to access <code>testObj</code>");'
|
||||
testString: assert(/testObj\s*?\[.*?\]/.test(code));
|
||||
- text: 您不应该直接将值<code>Montana</code>分配给变量<code>player</code> 。
|
||||
testString: 'assert(!code.match(/player\s*=\s*"|\"\s*Montana\s*"|\"\s*;/gi),"You should not assign the value <code>Montana</code> to the variable <code>player</code> directly.");'
|
||||
testString: assert(!code.match(/player\s*=\s*"|\'\s*Montana\s*"|\'\s*;/gi));
|
||||
- text: 您应该在括号表示法中使用变量<code>playerNumber</code>
|
||||
testString: 'assert(/testObj\s*?\[\s*playerNumber\s*\]/.test(code),"You should be using the variable <code>playerNumber</code> in your bracket notation");'
|
||||
testString: assert(/testObj\s*?\[\s*playerNumber\s*\]/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 将新属性添加到JavaScript对象
|
||||
```yml
|
||||
tests:
|
||||
- text: 将属性<code>"bark"</code>添加到<code>myDog</code> 。
|
||||
testString: 'assert(myDog.bark !== undefined, "Add the property <code>"bark"</code> to <code>myDog</code>.");'
|
||||
testString: assert(myDog.bark !== undefined);
|
||||
- text: 不要在设置部分添加<code>"bark"</code>
|
||||
testString: 'assert(!/bark[^\n]:/.test(code), "Do not add <code>"bark"</code> to the setup section");'
|
||||
testString: assert(!/bark[^\n]:/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 使用JavaScript添加两个数字
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>sum</code>应该等于<code>20</code>
|
||||
testString: 'assert(sum === 20, "<code>sum</code> should equal <code>20</code>");'
|
||||
testString: assert(sum === 20);
|
||||
- text: 使用<code>+</code>运算符
|
||||
testString: 'assert(/\+/.test(code), "Use the <code>+</code> operator");'
|
||||
testString: assert(/\+/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,21 +18,21 @@ localeTitle: 在交换机语句中添加默认选项
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>switchOfStuff("a")</code>的值应为“apple”
|
||||
testString: 'assert(switchOfStuff("a") === "apple", "<code>switchOfStuff("a")</code> should have a value of "apple"");'
|
||||
testString: assert(switchOfStuff("a") === "apple");
|
||||
- text: <code>switchOfStuff("b")</code>的值应为“bird”
|
||||
testString: 'assert(switchOfStuff("b") === "bird", "<code>switchOfStuff("b")</code> should have a value of "bird"");'
|
||||
testString: assert(switchOfStuff("b") === "bird");
|
||||
- text: <code>switchOfStuff("c")</code>的值应为“cat”
|
||||
testString: 'assert(switchOfStuff("c") === "cat", "<code>switchOfStuff("c")</code> should have a value of "cat"");'
|
||||
testString: assert(switchOfStuff("c") === "cat");
|
||||
- text: <code>switchOfStuff("d")</code>的值应为“stuff”
|
||||
testString: 'assert(switchOfStuff("d") === "stuff", "<code>switchOfStuff("d")</code> should have a value of "stuff"");'
|
||||
testString: assert(switchOfStuff("d") === "stuff");
|
||||
- text: <code>switchOfStuff(4)</code>的值应为“stuff”
|
||||
testString: 'assert(switchOfStuff(4) === "stuff", "<code>switchOfStuff(4)</code> should have a value of "stuff"");'
|
||||
testString: assert(switchOfStuff(4) === "stuff");
|
||||
- text: 您不应该使用任何<code>if</code>或<code>else</code>语句
|
||||
testString: 'assert(!/else/g.test(code) || !/if/g.test(code), "You should not use any <code>if</code> or <code>else</code> statements");'
|
||||
testString: assert(!/else/g.test(code) || !/if/g.test(code));
|
||||
- text: 您应该使用<code>default</code>语句
|
||||
testString: 'assert(switchOfStuff("string-to-trigger-default-case") === "stuff", "You should use a <code>default</code> statement");'
|
||||
testString: assert(switchOfStuff("string-to-trigger-default-case") === "stuff");
|
||||
- text: 你应该至少有3个<code>break</code>语句
|
||||
testString: 'assert(code.match(/break/g).length > 2, "You should have at least 3 <code>break</code> statements");'
|
||||
testString: assert(code.match(/break/g).length > 2);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 将变量附加到字符串
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>someAdjective</code>应设置为至少3个字符长的字符串
|
||||
testString: 'assert(typeof someAdjective !== "undefined" && someAdjective.length > 2, "<code>someAdjective</code> should be set to a string at least 3 characters long");'
|
||||
testString: assert(typeof someAdjective !== 'undefined' && someAdjective.length > 2);
|
||||
- text: 使用<code>+=</code>运算符将<code>someAdjective</code>附加到<code>myStr</code>
|
||||
testString: 'assert(code.match(/myStr\s*\+=\s*someAdjective\s*/).length > 0, "Append <code>someAdjective</code> to <code>myStr</code> using the <code>+=</code> operator");'
|
||||
testString: assert(code.match(/myStr\s*\+=\s*someAdjective\s*/).length > 0);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 具有返回值的分配
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>processed</code>的值应为<code>2</code>
|
||||
testString: 'assert(processed === 2, "<code>processed</code> should have a value of <code>2</code>");'
|
||||
testString: assert(processed === 2);
|
||||
- text: 您应该将<code>processArg</code>分配给已<code>processed</code>
|
||||
testString: 'assert(/processed\s*=\s*processArg\(\s*7\s*\)\s*;/.test(code), "You should assign <code>processArg</code> to <code>processed</code>");'
|
||||
testString: assert(/processed\s*=\s*processArg\(\s*7\s*\)/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,15 +18,15 @@ localeTitle: 构建JavaScript对象
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myDog</code>应该包含属性<code>name</code> ,它应该是一个<code>string</code> 。
|
||||
testString: 'assert((function(z){if(z.hasOwnProperty("name") && z.name !== undefined && typeof z.name === "string"){return true;}else{return false;}})(myDog), "<code>myDog</code> should contain the property <code>name</code> and it should be a <code>string</code>.");'
|
||||
testString: assert((function(z){if(z.hasOwnProperty("name") && z.name !== undefined && typeof z.name === "string"){return true;}else{return false;}})(myDog));
|
||||
- text: <code>myDog</code>应该包含属性<code>legs</code> ,它应该是一个<code>number</code> 。
|
||||
testString: 'assert((function(z){if(z.hasOwnProperty("legs") && z.legs !== undefined && typeof z.legs === "number"){return true;}else{return false;}})(myDog), "<code>myDog</code> should contain the property <code>legs</code> and it should be a <code>number</code>.");'
|
||||
testString: assert((function(z){if(z.hasOwnProperty("legs") && z.legs !== undefined && typeof z.legs === "number"){return true;}else{return false;}})(myDog));
|
||||
- text: <code>myDog</code>应该包含属性<code>tails</code> ,它应该是一个<code>number</code> 。
|
||||
testString: 'assert((function(z){if(z.hasOwnProperty("tails") && z.tails !== undefined && typeof z.tails === "number"){return true;}else{return false;}})(myDog), "<code>myDog</code> should contain the property <code>tails</code> and it should be a <code>number</code>.");'
|
||||
testString: assert((function(z){if(z.hasOwnProperty("tails") && z.tails !== undefined && typeof z.tails === "number"){return true;}else{return false;}})(myDog));
|
||||
- text: <code>myDog</code>应该包含属性<code>friends</code> ,它应该是一个<code>array</code> 。
|
||||
testString: 'assert((function(z){if(z.hasOwnProperty("friends") && z.friends !== undefined && Array.isArray(z.friends)){return true;}else{return false;}})(myDog), "<code>myDog</code> should contain the property <code>friends</code> and it should be an <code>array</code>.");'
|
||||
testString: assert((function(z){if(z.hasOwnProperty("friends") && z.friends !== undefined && Array.isArray(z.friends)){return true;}else{return false;}})(myDog));
|
||||
- text: <code>myDog</code>应该只包含所有给定的属性。
|
||||
testString: 'assert((function(z){return Object.keys(z).length === 4;})(myDog), "<code>myDog</code> should only contain all the given properties.");'
|
||||
testString: assert((function(z){return Object.keys(z).length === 4;})(myDog));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,31 +18,31 @@ localeTitle: 链接如果其他声明
|
||||
```yml
|
||||
tests:
|
||||
- text: 你应该至少有四个<code>else</code>语句
|
||||
testString: 'assert(code.match(/else/g).length > 3, "You should have at least four <code>else</code> statements");'
|
||||
testString: assert(code.match(/else/g).length > 3);
|
||||
- text: 你应该至少有四个<code>if</code>语句
|
||||
testString: 'assert(code.match(/if/g).length > 3, "You should have at least four <code>if</code> statements");'
|
||||
testString: assert(code.match(/if/g).length > 3);
|
||||
- text: 你应该至少有一个<code>return</code>语句
|
||||
testString: 'assert(code.match(/return/g).length >= 1, "You should have at least one <code>return</code> statement");'
|
||||
testString: assert(code.match(/return/g).length >= 1);
|
||||
- text: <code>testSize(0)</code>应该返回“Tiny”
|
||||
testString: 'assert(testSize(0) === "Tiny", "<code>testSize(0)</code> should return "Tiny"");'
|
||||
testString: assert(testSize(0) === "Tiny");
|
||||
- text: <code>testSize(4)</code>应该返回“Tiny”
|
||||
testString: 'assert(testSize(4) === "Tiny", "<code>testSize(4)</code> should return "Tiny"");'
|
||||
testString: assert(testSize(4) === "Tiny");
|
||||
- text: <code>testSize(5)</code>应返回“Small”
|
||||
testString: 'assert(testSize(5) === "Small", "<code>testSize(5)</code> should return "Small"");'
|
||||
testString: assert(testSize(5) === "Small");
|
||||
- text: <code>testSize(8)</code>应该返回“Small”
|
||||
testString: 'assert(testSize(8) === "Small", "<code>testSize(8)</code> should return "Small"");'
|
||||
testString: assert(testSize(8) === "Small");
|
||||
- text: <code>testSize(10)</code>应该返回“Medium”
|
||||
testString: 'assert(testSize(10) === "Medium", "<code>testSize(10)</code> should return "Medium"");'
|
||||
testString: assert(testSize(10) === "Medium");
|
||||
- text: <code>testSize(14)</code>应返回“Medium”
|
||||
testString: 'assert(testSize(14) === "Medium", "<code>testSize(14)</code> should return "Medium"");'
|
||||
testString: assert(testSize(14) === "Medium");
|
||||
- text: <code>testSize(15)</code>应该返回“Large”
|
||||
testString: 'assert(testSize(15) === "Large", "<code>testSize(15)</code> should return "Large"");'
|
||||
testString: assert(testSize(15) === "Large");
|
||||
- text: <code>testSize(17)</code>应该返回“Large”
|
||||
testString: 'assert(testSize(17) === "Large", "<code>testSize(17)</code> should return "Large"");'
|
||||
testString: assert(testSize(17) === "Large");
|
||||
- text: <code>testSize(20)</code>应该返回“巨大”
|
||||
testString: 'assert(testSize(20) === "Huge", "<code>testSize(20)</code> should return "Huge"");'
|
||||
testString: assert(testSize(20) === "Huge");
|
||||
- text: <code>testSize(25)</code>应该返回“巨大”
|
||||
testString: 'assert(testSize(25) === "Huge", "<code>testSize(25)</code> should return "Huge"");'
|
||||
testString: assert(testSize(25) === "Huge");
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 评论您的JavaScript代码
|
||||
```yml
|
||||
tests:
|
||||
- text: 创建一个包含至少五个字母的<code>//</code>样式注释。
|
||||
testString: 'assert(code.match(/(\/\/)...../g), "Create a <code>//</code> style comment that contains at least five letters.");'
|
||||
testString: assert(code.match(/(\/\/)...../g));
|
||||
- text: 创建包含至少五个字母的<code>/* */</code>样式注释。
|
||||
testString: 'assert(code.match(/(\/\*)([^\/]{5,})(?=\*\/)/gm), "Create a <code>/* */</code> style comment that contains at least five letters.");'
|
||||
testString: assert(code.match(/(\/\*)([^\/]{5,})(?=\*\/)/gm));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,13 +18,13 @@ localeTitle: 与平等算子的比较
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>testEqual(10)</code>应该返回“Not Equal”
|
||||
testString: 'assert(testEqual(10) === "Not Equal", "<code>testEqual(10)</code> should return "Not Equal"");'
|
||||
testString: assert(testEqual(10) === "Not Equal");
|
||||
- text: <code>testEqual(12)</code>应返回“Equal”
|
||||
testString: 'assert(testEqual(12) === "Equal", "<code>testEqual(12)</code> should return "Equal"");'
|
||||
testString: assert(testEqual(12) === "Equal");
|
||||
- text: <code>testEqual("12")</code>应返回“Equal”
|
||||
testString: 'assert(testEqual("12") === "Equal", "<code>testEqual("12")</code> should return "Equal"");'
|
||||
testString: assert(testEqual("12") === "Equal");
|
||||
- text: 您应该使用<code>==</code>运算符
|
||||
testString: 'assert(code.match(/==/g) && !code.match(/===/g), "You should use the <code>==</code> operator");'
|
||||
testString: assert(code.match(/==/g) && !code.match(/===/g));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,21 +18,21 @@ localeTitle: 与大于运营商的比较
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>testGreaterThan(0)</code>应返回“10或Under”
|
||||
testString: 'assert(testGreaterThan(0) === "10 or Under", "<code>testGreaterThan(0)</code> should return "10 or Under"");'
|
||||
testString: assert(testGreaterThan(0) === "10 or Under");
|
||||
- text: <code>testGreaterThan(10)</code>应返回“10或Under”
|
||||
testString: 'assert(testGreaterThan(10) === "10 or Under", "<code>testGreaterThan(10)</code> should return "10 or Under"");'
|
||||
testString: assert(testGreaterThan(10) === "10 or Under");
|
||||
- text: <code>testGreaterThan(11)</code>应该返回“Over 10”
|
||||
testString: 'assert(testGreaterThan(11) === "Over 10", "<code>testGreaterThan(11)</code> should return "Over 10"");'
|
||||
testString: assert(testGreaterThan(11) === "Over 10");
|
||||
- text: <code>testGreaterThan(99)</code>应该返回“Over 10”
|
||||
testString: 'assert(testGreaterThan(99) === "Over 10", "<code>testGreaterThan(99)</code> should return "Over 10"");'
|
||||
testString: assert(testGreaterThan(99) === "Over 10");
|
||||
- text: <code>testGreaterThan(100)</code>应该返回“Over 10”
|
||||
testString: 'assert(testGreaterThan(100) === "Over 10", "<code>testGreaterThan(100)</code> should return "Over 10"");'
|
||||
testString: assert(testGreaterThan(100) === "Over 10");
|
||||
- text: <code>testGreaterThan(101)</code>应返回“超过100”
|
||||
testString: 'assert(testGreaterThan(101) === "Over 100", "<code>testGreaterThan(101)</code> should return "Over 100"");'
|
||||
testString: assert(testGreaterThan(101) === "Over 100");
|
||||
- text: <code>testGreaterThan(150)</code>应该返回“超过100”
|
||||
testString: 'assert(testGreaterThan(150) === "Over 100", "<code>testGreaterThan(150)</code> should return "Over 100"");'
|
||||
testString: assert(testGreaterThan(150) === "Over 100");
|
||||
- text: 您应该至少使用<code>></code>运算符两次
|
||||
testString: 'assert(code.match(/val\s*>\s*("|")*\d+("|")*/g).length > 1, "You should use the <code>></code> operator at least twice");'
|
||||
testString: assert(code.match(/val\s*>\s*('|")*\d+('|")*/g).length > 1);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,21 +18,21 @@ localeTitle: 与大于或等于运算符的比较
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>testGreaterOrEqual(0)</code>应返回“小于10”
|
||||
testString: 'assert(testGreaterOrEqual(0) === "Less than 10", "<code>testGreaterOrEqual(0)</code> should return "Less than 10"");'
|
||||
testString: assert(testGreaterOrEqual(0) === "Less than 10");
|
||||
- text: <code>testGreaterOrEqual(9)</code>应返回“小于10”
|
||||
testString: 'assert(testGreaterOrEqual(9) === "Less than 10", "<code>testGreaterOrEqual(9)</code> should return "Less than 10"");'
|
||||
testString: assert(testGreaterOrEqual(9) === "Less than 10");
|
||||
- text: <code>testGreaterOrEqual(10)</code>应返回“10或Over”
|
||||
testString: 'assert(testGreaterOrEqual(10) === "10 or Over", "<code>testGreaterOrEqual(10)</code> should return "10 or Over"");'
|
||||
testString: assert(testGreaterOrEqual(10) === "10 or Over");
|
||||
- text: <code>testGreaterOrEqual(11)</code>应返回“10或Over”
|
||||
testString: 'assert(testGreaterOrEqual(11) === "10 or Over", "<code>testGreaterOrEqual(11)</code> should return "10 or Over"");'
|
||||
testString: assert(testGreaterOrEqual(11) === "10 or Over");
|
||||
- text: <code>testGreaterOrEqual(19)</code>应返回“10或Over”
|
||||
testString: 'assert(testGreaterOrEqual(19) === "10 or Over", "<code>testGreaterOrEqual(19)</code> should return "10 or Over"");'
|
||||
testString: assert(testGreaterOrEqual(19) === "10 or Over");
|
||||
- text: <code>testGreaterOrEqual(100)</code>应该返回“20或Over”
|
||||
testString: 'assert(testGreaterOrEqual(100) === "20 or Over", "<code>testGreaterOrEqual(100)</code> should return "20 or Over"");'
|
||||
testString: assert(testGreaterOrEqual(100) === "20 or Over");
|
||||
- text: <code>testGreaterOrEqual(21)</code>应返回“20或Over”
|
||||
testString: 'assert(testGreaterOrEqual(21) === "20 or Over", "<code>testGreaterOrEqual(21)</code> should return "20 or Over"");'
|
||||
testString: assert(testGreaterOrEqual(21) === "20 or Over");
|
||||
- text: 您应该使用<code>>=</code>运算符至少两次
|
||||
testString: 'assert(code.match(/val\s*>=\s*("|")*\d+("|")*/g).length > 1, "You should use the <code>>=</code> operator at least twice");'
|
||||
testString: assert(code.match(/val\s*>=\s*('|")*\d+('|")*/g).length > 1);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,17 +18,17 @@ localeTitle: 与不等式算子的比较
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>testNotEqual(99)</code>应返回“Equal”
|
||||
testString: 'assert(testNotEqual(99) === "Equal", "<code>testNotEqual(99)</code> should return "Equal"");'
|
||||
testString: assert(testNotEqual(99) === "Equal");
|
||||
- text: <code>testNotEqual("99")</code>应该返回“Equal”
|
||||
testString: 'assert(testNotEqual("99") === "Equal", "<code>testNotEqual("99")</code> should return "Equal"");'
|
||||
testString: assert(testNotEqual("99") === "Equal");
|
||||
- text: <code>testNotEqual(12)</code>应该返回“Not Equal”
|
||||
testString: 'assert(testNotEqual(12) === "Not Equal", "<code>testNotEqual(12)</code> should return "Not Equal"");'
|
||||
testString: assert(testNotEqual(12) === "Not Equal");
|
||||
- text: <code>testNotEqual("12")</code>应该返回“Not Equal”
|
||||
testString: 'assert(testNotEqual("12") === "Not Equal", "<code>testNotEqual("12")</code> should return "Not Equal"");'
|
||||
testString: assert(testNotEqual("12") === "Not Equal");
|
||||
- text: <code>testNotEqual("bob")</code>应返回“Not Equal”
|
||||
testString: 'assert(testNotEqual("bob") === "Not Equal", "<code>testNotEqual("bob")</code> should return "Not Equal"");'
|
||||
testString: assert(testNotEqual("bob") === "Not Equal");
|
||||
- text: 你应该使用<code>!=</code>运算符
|
||||
testString: 'assert(code.match(/(?!!==)!=/), "You should use the <code>!=</code> operator");'
|
||||
testString: assert(code.match(/(?!!==)!=/));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,19 +18,19 @@ localeTitle: 与小于算子的比较
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>testLessThan(0)</code>应该返回“25岁以下”
|
||||
testString: 'assert(testLessThan(0) === "Under 25", "<code>testLessThan(0)</code> should return "Under 25"");'
|
||||
testString: assert(testLessThan(0) === "Under 25");
|
||||
- text: <code>testLessThan(24)</code>应该返回“25岁以下”
|
||||
testString: 'assert(testLessThan(24) === "Under 25", "<code>testLessThan(24)</code> should return "Under 25"");'
|
||||
testString: assert(testLessThan(24) === "Under 25");
|
||||
- text: <code>testLessThan(25)</code>应该返回“55岁以下”
|
||||
testString: 'assert(testLessThan(25) === "Under 55", "<code>testLessThan(25)</code> should return "Under 55"");'
|
||||
testString: assert(testLessThan(25) === "Under 55");
|
||||
- text: <code>testLessThan(54)</code>应该返回“55岁以下”
|
||||
testString: 'assert(testLessThan(54) === "Under 55", "<code>testLessThan(54)</code> should return "Under 55"");'
|
||||
testString: assert(testLessThan(54) === "Under 55");
|
||||
- text: <code>testLessThan(55)</code>应返回“55或以上”
|
||||
testString: 'assert(testLessThan(55) === "55 or Over", "<code>testLessThan(55)</code> should return "55 or Over"");'
|
||||
testString: assert(testLessThan(55) === "55 or Over");
|
||||
- text: <code>testLessThan(99)</code>应返回“55或以上”
|
||||
testString: 'assert(testLessThan(99) === "55 or Over", "<code>testLessThan(99)</code> should return "55 or Over"");'
|
||||
testString: assert(testLessThan(99) === "55 or Over");
|
||||
- text: 您应该至少使用<code><</code>运算符两次
|
||||
testString: 'assert(code.match(/val\s*<\s*("|")*\d+("|")*/g).length > 1, "You should use the <code><</code> operator at least twice");'
|
||||
testString: assert(code.match(/val\s*<\s*('|")*\d+('|")*/g).length > 1);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,21 +18,21 @@ localeTitle: 与小于或等于运算符的比较
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>testLessOrEqual(0)</code>应该返回“小于或等于12”
|
||||
testString: 'assert(testLessOrEqual(0) === "Smaller Than or Equal to 12", "<code>testLessOrEqual(0)</code> should return "Smaller Than or Equal to 12"");'
|
||||
testString: assert(testLessOrEqual(0) === "Smaller Than or Equal to 12");
|
||||
- text: <code>testLessOrEqual(11)</code>应返回“小于或等于12”
|
||||
testString: 'assert(testLessOrEqual(11) === "Smaller Than or Equal to 12", "<code>testLessOrEqual(11)</code> should return "Smaller Than or Equal to 12"");'
|
||||
testString: assert(testLessOrEqual(11) === "Smaller Than or Equal to 12");
|
||||
- text: <code>testLessOrEqual(12)</code>应返回“小于或等于12”
|
||||
testString: 'assert(testLessOrEqual(12) === "Smaller Than or Equal to 12", "<code>testLessOrEqual(12)</code> should return "Smaller Than or Equal to 12"");'
|
||||
testString: assert(testLessOrEqual(12) === "Smaller Than or Equal to 12");
|
||||
- text: <code>testLessOrEqual(23)</code>应返回“小于或等于24”
|
||||
testString: 'assert(testLessOrEqual(23) === "Smaller Than or Equal to 24", "<code>testLessOrEqual(23)</code> should return "Smaller Than or Equal to 24"");'
|
||||
testString: assert(testLessOrEqual(23) === "Smaller Than or Equal to 24");
|
||||
- text: <code>testLessOrEqual(24)</code>应返回“小于或等于24”
|
||||
testString: 'assert(testLessOrEqual(24) === "Smaller Than or Equal to 24", "<code>testLessOrEqual(24)</code> should return "Smaller Than or Equal to 24"");'
|
||||
testString: assert(testLessOrEqual(24) === "Smaller Than or Equal to 24");
|
||||
- text: <code>testLessOrEqual(25)</code>应该返回“超过24”
|
||||
testString: 'assert(testLessOrEqual(25) === "More Than 24", "<code>testLessOrEqual(25)</code> should return "More Than 24"");'
|
||||
testString: assert(testLessOrEqual(25) === "More Than 24");
|
||||
- text: <code>testLessOrEqual(55)</code>应该返回“超过24”
|
||||
testString: 'assert(testLessOrEqual(55) === "More Than 24", "<code>testLessOrEqual(55)</code> should return "More Than 24"");'
|
||||
testString: assert(testLessOrEqual(55) === "More Than 24");
|
||||
- text: 你应该至少使用<code><=</code>运算符两次
|
||||
testString: 'assert(code.match(/val\s*<=\s*("|")*\d+("|")*/g).length > 1, "You should use the <code><=</code> operator at least twice");'
|
||||
testString: assert(code.match(/val\s*<=\s*('|")*\d+('|")*/g).length > 1);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,13 +18,13 @@ localeTitle: 与严格平等算子的比较
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>testStrict(10)</code>应返回“Not Equal”
|
||||
testString: 'assert(testStrict(10) === "Not Equal", "<code>testStrict(10)</code> should return "Not Equal"");'
|
||||
testString: assert(testStrict(10) === "Not Equal");
|
||||
- text: <code>testStrict(7)</code>应返回“Equal”
|
||||
testString: 'assert(testStrict(7) === "Equal", "<code>testStrict(7)</code> should return "Equal"");'
|
||||
testString: assert(testStrict(7) === "Equal");
|
||||
- text: <code>testStrict("7")</code>应返回“Not Equal”
|
||||
testString: 'assert(testStrict("7") === "Not Equal", "<code>testStrict("7")</code> should return "Not Equal"");'
|
||||
testString: assert(testStrict("7") === "Not Equal");
|
||||
- text: 您应该使用<code>===</code>运算符
|
||||
testString: 'assert(code.match(/(val\s*===\s*\d+)|(\d+\s*===\s*val)/g).length > 0, "You should use the <code>===</code> operator");'
|
||||
testString: assert(code.match(/(val\s*===\s*\d+)|(\d+\s*===\s*val)/g).length > 0);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,15 +18,15 @@ localeTitle: 与严格不等式算子的比较
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>testStrictNotEqual(17)</code>应返回“Equal”
|
||||
testString: 'assert(testStrictNotEqual(17) === "Equal", "<code>testStrictNotEqual(17)</code> should return "Equal"");'
|
||||
testString: assert(testStrictNotEqual(17) === "Equal");
|
||||
- text: <code>testStrictNotEqual("17")</code>应返回“Not Equal”
|
||||
testString: 'assert(testStrictNotEqual("17") === "Not Equal", "<code>testStrictNotEqual("17")</code> should return "Not Equal"");'
|
||||
testString: assert(testStrictNotEqual("17") === "Not Equal");
|
||||
- text: <code>testStrictNotEqual(12)</code>应该返回“Not Equal”
|
||||
testString: 'assert(testStrictNotEqual(12) === "Not Equal", "<code>testStrictNotEqual(12)</code> should return "Not Equal"");'
|
||||
testString: assert(testStrictNotEqual(12) === "Not Equal");
|
||||
- text: <code>testStrictNotEqual("bob")</code>应返回“Not Equal”
|
||||
testString: 'assert(testStrictNotEqual("bob") === "Not Equal", "<code>testStrictNotEqual("bob")</code> should return "Not Equal"");'
|
||||
testString: assert(testStrictNotEqual("bob") === "Not Equal");
|
||||
- text: 你应该使用<code>!==</code>运算符
|
||||
testString: 'assert(code.match(/(val\s*!==\s*\d+)|(\d+\s*!==\s*val)/g).length > 0, "You should use the <code>!==</code> operator");'
|
||||
testString: assert(code.match(/(val\s*!==\s*\d+)|(\d+\s*!==\s*val)/g).length > 0);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,25 +18,25 @@ localeTitle: 与逻辑和运算符的比较
|
||||
```yml
|
||||
tests:
|
||||
- text: 你应该使用一次<code>&&</code>运算符
|
||||
testString: 'assert(code.match(/&&/g).length === 1, "You should use the <code>&&</code> operator once");'
|
||||
testString: assert(code.match(/&&/g).length === 1);
|
||||
- text: 你应该只有一个<code>if</code>语句
|
||||
testString: 'assert(code.match(/if/g).length === 1, "You should only have one <code>if</code> statement");'
|
||||
testString: assert(code.match(/if/g).length === 1);
|
||||
- text: <code>testLogicalAnd(0)</code>应返回“否”
|
||||
testString: 'assert(testLogicalAnd(0) === "No", "<code>testLogicalAnd(0)</code> should return "No"");'
|
||||
testString: assert(testLogicalAnd(0) === "No");
|
||||
- text: <code>testLogicalAnd(24)</code>应返回“否”
|
||||
testString: 'assert(testLogicalAnd(24) === "No", "<code>testLogicalAnd(24)</code> should return "No"");'
|
||||
testString: assert(testLogicalAnd(24) === "No");
|
||||
- text: <code>testLogicalAnd(25)</code>应返回“是”
|
||||
testString: 'assert(testLogicalAnd(25) === "Yes", "<code>testLogicalAnd(25)</code> should return "Yes"");'
|
||||
testString: assert(testLogicalAnd(25) === "Yes");
|
||||
- text: <code>testLogicalAnd(30)</code>应该返回“是”
|
||||
testString: 'assert(testLogicalAnd(30) === "Yes", "<code>testLogicalAnd(30)</code> should return "Yes"");'
|
||||
testString: assert(testLogicalAnd(30) === "Yes");
|
||||
- text: <code>testLogicalAnd(50)</code>应该返回“是”
|
||||
testString: 'assert(testLogicalAnd(50) === "Yes", "<code>testLogicalAnd(50)</code> should return "Yes"");'
|
||||
testString: assert(testLogicalAnd(50) === "Yes");
|
||||
- text: <code>testLogicalAnd(51)</code>应返回“否”
|
||||
testString: 'assert(testLogicalAnd(51) === "No", "<code>testLogicalAnd(51)</code> should return "No"");'
|
||||
testString: assert(testLogicalAnd(51) === "No");
|
||||
- text: <code>testLogicalAnd(75)</code>应返回“否”
|
||||
testString: 'assert(testLogicalAnd(75) === "No", "<code>testLogicalAnd(75)</code> should return "No"");'
|
||||
testString: assert(testLogicalAnd(75) === "No");
|
||||
- text: <code>testLogicalAnd(80)</code>应返回“否”
|
||||
testString: 'assert(testLogicalAnd(80) === "No", "<code>testLogicalAnd(80)</code> should return "No"");'
|
||||
testString: assert(testLogicalAnd(80) === "No");
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,25 +18,25 @@ localeTitle: 与逻辑或运算符的比较
|
||||
```yml
|
||||
tests:
|
||||
- text: 你应该使用<code>||</code>操作员一次
|
||||
testString: 'assert(code.match(/\|\|/g).length === 1, "You should use the <code>||</code> operator once");'
|
||||
testString: assert(code.match(/\|\|/g).length === 1);
|
||||
- text: 你应该只有一个<code>if</code>语句
|
||||
testString: 'assert(code.match(/if/g).length === 1, "You should only have one <code>if</code> statement");'
|
||||
testString: assert(code.match(/if/g).length === 1);
|
||||
- text: <code>testLogicalOr(0)</code>应返回“Outside”
|
||||
testString: 'assert(testLogicalOr(0) === "Outside", "<code>testLogicalOr(0)</code> should return "Outside"");'
|
||||
testString: assert(testLogicalOr(0) === "Outside");
|
||||
- text: <code>testLogicalOr(9)</code>应返回“Outside”
|
||||
testString: 'assert(testLogicalOr(9) === "Outside", "<code>testLogicalOr(9)</code> should return "Outside"");'
|
||||
testString: assert(testLogicalOr(9) === "Outside");
|
||||
- text: <code>testLogicalOr(10)</code>应返回“Inside”
|
||||
testString: 'assert(testLogicalOr(10) === "Inside", "<code>testLogicalOr(10)</code> should return "Inside"");'
|
||||
testString: assert(testLogicalOr(10) === "Inside");
|
||||
- text: <code>testLogicalOr(15)</code>应返回“Inside”
|
||||
testString: 'assert(testLogicalOr(15) === "Inside", "<code>testLogicalOr(15)</code> should return "Inside"");'
|
||||
testString: assert(testLogicalOr(15) === "Inside");
|
||||
- text: <code>testLogicalOr(19)</code>应该返回“Inside”
|
||||
testString: 'assert(testLogicalOr(19) === "Inside", "<code>testLogicalOr(19)</code> should return "Inside"");'
|
||||
testString: assert(testLogicalOr(19) === "Inside");
|
||||
- text: <code>testLogicalOr(20)</code>应该返回“Inside”
|
||||
testString: 'assert(testLogicalOr(20) === "Inside", "<code>testLogicalOr(20)</code> should return "Inside"");'
|
||||
testString: assert(testLogicalOr(20) === "Inside");
|
||||
- text: <code>testLogicalOr(21)</code>应该返回“Outside”
|
||||
testString: 'assert(testLogicalOr(21) === "Outside", "<code>testLogicalOr(21)</code> should return "Outside"");'
|
||||
testString: assert(testLogicalOr(21) === "Outside");
|
||||
- text: <code>testLogicalOr(25)</code>应返回“Outside”
|
||||
testString: 'assert(testLogicalOr(25) === "Outside", "<code>testLogicalOr(25)</code> should return "Outside"");'
|
||||
testString: assert(testLogicalOr(25) === "Outside");
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,15 +18,15 @@ localeTitle: 具有增强加法的复合赋值
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>a</code>应该等于<code>15</code>
|
||||
testString: 'assert(a === 15, "<code>a</code> should equal <code>15</code>");'
|
||||
testString: assert(a === 15);
|
||||
- text: <code>b</code>应该等于<code>26</code>
|
||||
testString: 'assert(b === 26, "<code>b</code> should equal <code>26</code>");'
|
||||
testString: assert(b === 26);
|
||||
- text: <code>c</code>应该等于<code>19</code>
|
||||
testString: 'assert(c === 19, "<code>c</code> should equal <code>19</code>");'
|
||||
testString: assert(c === 19);
|
||||
- text: 您应该为每个变量使用<code>+=</code>运算符
|
||||
testString: 'assert(code.match(/\+=/g).length === 3, "You should use the <code>+=</code> operator for each variable");'
|
||||
testString: assert(code.match(/\+=/g).length === 3);
|
||||
- text: 不要修改行上方的代码
|
||||
testString: 'assert(/var a = 3;/.test(code) && /var b = 17;/.test(code) && /var c = 12;/.test(code), "Do not modify the code above the line");'
|
||||
testString: assert(/var a = 3;/.test(code) && /var b = 17;/.test(code) && /var c = 12;/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,15 +18,15 @@ localeTitle: 具有增广划分的复合赋值
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>a</code>应该等于<code>4</code>
|
||||
testString: 'assert(a === 4, "<code>a</code> should equal <code>4</code>");'
|
||||
testString: assert(a === 4);
|
||||
- text: <code>b</code>应该等于<code>27</code>
|
||||
testString: 'assert(b === 27, "<code>b</code> should equal <code>27</code>");'
|
||||
testString: assert(b === 27);
|
||||
- text: <code>c</code>应该等于<code>3</code>
|
||||
testString: 'assert(c === 3, "<code>c</code> should equal <code>3</code>");'
|
||||
testString: assert(c === 3);
|
||||
- text: 您应该为每个变量使用<code>/=</code>运算符
|
||||
testString: 'assert(code.match(/\/=/g).length === 3, "You should use the <code>/=</code> operator for each variable");'
|
||||
testString: assert(code.match(/\/=/g).length === 3);
|
||||
- text: 不要修改行上方的代码
|
||||
testString: 'assert(/var a = 48;/.test(code) && /var b = 108;/.test(code) && /var c = 33;/.test(code), "Do not modify the code above the line");'
|
||||
testString: assert(/var a = 48;/.test(code) && /var b = 108;/.test(code) && /var c = 33;/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,15 +18,15 @@ localeTitle: 具有增广乘法的复合赋值
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>a</code>应该等于<code>25</code>
|
||||
testString: 'assert(a === 25, "<code>a</code> should equal <code>25</code>");'
|
||||
testString: assert(a === 25);
|
||||
- text: <code>b</code>应该等于<code>36</code>
|
||||
testString: 'assert(b === 36, "<code>b</code> should equal <code>36</code>");'
|
||||
testString: assert(b === 36);
|
||||
- text: <code>c</code>应该等于<code>46</code>
|
||||
testString: 'assert(c === 46, "<code>c</code> should equal <code>46</code>");'
|
||||
testString: assert(c === 46);
|
||||
- text: 您应该为每个变量使用<code>*=</code>运算符
|
||||
testString: 'assert(code.match(/\*=/g).length === 3, "You should use the <code>*=</code> operator for each variable");'
|
||||
testString: assert(code.match(/\*=/g).length === 3);
|
||||
- text: 不要修改行上方的代码
|
||||
testString: 'assert(/var a = 5;/.test(code) && /var b = 12;/.test(code) && /var c = 4\.6;/.test(code), "Do not modify the code above the line");'
|
||||
testString: assert(/var a = 5;/.test(code) && /var b = 12;/.test(code) && /var c = 4\.6;/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,15 +18,15 @@ localeTitle: 具有增广减法的复合赋值
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>a</code>应该等于<code>5</code>
|
||||
testString: 'assert(a === 5, "<code>a</code> should equal <code>5</code>");'
|
||||
testString: assert(a === 5);
|
||||
- text: <code>b</code>应该等于<code>-6</code>
|
||||
testString: 'assert(b === -6, "<code>b</code> should equal <code>-6</code>");'
|
||||
testString: assert(b === -6);
|
||||
- text: <code>c</code>应该等于<code>2</code>
|
||||
testString: 'assert(c === 2, "<code>c</code> should equal <code>2</code>");'
|
||||
testString: assert(c === 2);
|
||||
- text: 您应该为每个变量使用<code>-=</code>运算符
|
||||
testString: 'assert(code.match(/-=/g).length === 3, "You should use the <code>-=</code> operator for each variable");'
|
||||
testString: assert(code.match(/-=/g).length === 3);
|
||||
- text: 不要修改行上方的代码
|
||||
testString: 'assert(/var a = 11;/.test(code) && /var b = 9;/.test(code) && /var c = 3;/.test(code), "Do not modify the code above the line");'
|
||||
testString: assert(/var a = 11;/.test(code) && /var b = 9;/.test(code) && /var c = 3;/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,13 +18,13 @@ localeTitle: 用Plus运算符连接字符串
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myStr</code>应该有一个值<code>This is the start. This is the end.</code>
|
||||
testString: 'assert(myStr === "This is the start. This is the end.", "<code>myStr</code> should have a value of <code>This is the start. This is the end.</code>");'
|
||||
testString: assert(myStr === "This is the start. This is the end.");
|
||||
- text: 使用<code>+</code>运算符构建<code>myStr</code>
|
||||
testString: 'assert(code.match(/([""]).*([""])\s*\+\s*([""]).*([""])/g).length > 1, "Use the <code>+</code> operator to build <code>myStr</code>");'
|
||||
testString: assert(code.match(/(["']).*(["'])\s*\+\s*(["']).*(["'])/g).length > 1);
|
||||
- text: 应使用<code>var</code>关键字创建<code>myStr</code> 。
|
||||
testString: 'assert(/var\s+myStr/.test(code), "<code>myStr</code> should be created using the <code>var</code> keyword.");'
|
||||
testString: assert(/var\s+myStr/.test(code));
|
||||
- text: 确保将结果分配给<code>myStr</code>变量。
|
||||
testString: 'assert(/myStr\s*=/.test(code), "Make sure to assign the result to the <code>myStr</code> variable.");'
|
||||
testString: assert(/myStr\s*=/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 使用Plus Equals运算符连接字符串
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myStr</code>应该有一个值<code>This is the first sentence. This is the second sentence.</code>
|
||||
testString: 'assert(myStr === "This is the first sentence. This is the second sentence.", "<code>myStr</code> should have a value of <code>This is the first sentence. This is the second sentence.</code>");'
|
||||
testString: assert(myStr === "This is the first sentence. This is the second sentence.");
|
||||
- text: 使用<code>+=</code>运算符构建<code>myStr</code>
|
||||
testString: 'assert(code.match(/\w\s*\+=\s*[""]/g).length > 1 && code.match(/\w\s*\=\s*[""]/g).length > 1, "Use the <code>+=</code> operator to build <code>myStr</code>");'
|
||||
testString: assert(code.match(/\w\s*\+=\s*["']/g).length > 1 && code.match(/\w\s*\=\s*["']/g).length > 1);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 用变量构造字符串
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myName</code>应设置为至少3个字符长的字符串
|
||||
testString: 'assert(typeof myName !== "undefined" && myName.length > 2, "<code>myName</code> should be set to a string at least 3 characters long");'
|
||||
testString: assert(typeof myName !== 'undefined' && myName.length > 2);
|
||||
- text: 使用两个<code>+</code>运算符在其中构建<code>myStr</code> with <code>myName</code>
|
||||
testString: 'assert(code.match(/[""]\s*\+\s*myName\s*\+\s*[""]/g).length > 0, "Use two <code>+</code> operators to build <code>myStr</code> with <code>myName</code> inside it");'
|
||||
testString: assert(code.match(/["']\s*\+\s*myName\s*\+\s*["']/g).length > 0);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,11 +18,11 @@ localeTitle: 用For循环向后计数
|
||||
```yml
|
||||
tests:
|
||||
- text: 你应该为此使用<code>for</code>循环。
|
||||
testString: 'assert(code.match(/for\s*\(/g).length > 1, "You should be using a <code>for</code> loop for this.");'
|
||||
testString: assert(code.match(/for\s*\(/g).length > 1);
|
||||
- text: 你应该使用数组方法<code>push</code> 。
|
||||
testString: 'assert(code.match(/myArray.push/), "You should be using the array method <code>push</code>.");'
|
||||
testString: assert(code.match(/myArray.push/));
|
||||
- text: '<code>myArray</code>应该等于<code>[9,7,5,3,1]</code> 。'
|
||||
testString: 'assert.deepEqual(myArray, [9,7,5,3,1], "<code>myArray</code> should equal <code>[9,7,5,3,1]</code>.");'
|
||||
testString: assert.deepEqual(myArray, [9,7,5,3,1]);
|
||||
|
||||
```
|
||||
|
||||
|
@ -19,19 +19,19 @@ localeTitle: 计数卡
|
||||
```yml
|
||||
tests:
|
||||
- text: 牌序列<code>5 Bet</code>应该返回<code>5 Bet</code>
|
||||
testString: 'assert((function(){ count = 0; cc(2);cc(3);cc(4);cc(5);var out = cc(6); if(out === "5 Bet") {return true;} return false; })(), "Cards Sequence 2, 3, 4, 5, 6 should return <code>5 Bet</code>");'
|
||||
testString: assert((function(){ count = 0; cc(2);cc(3);cc(4);cc(5);var out = cc(6); if(out === "5 Bet") {return true;} return false; })());
|
||||
- text: '卡片序列7,8,9应返回<code>0 Hold</code>'
|
||||
testString: 'assert((function(){ count = 0; cc(7);cc(8);var out = cc(9); if(out === "0 Hold") {return true;} return false; })(), "Cards Sequence 7, 8, 9 should return <code>0 Hold</code>");'
|
||||
testString: assert((function(){ count = 0; cc(7);cc(8);var out = cc(9); if(out === "0 Hold") {return true;} return false; })());
|
||||
- text: 卡序列10,J,Q,K,A应返回<code>-5 Hold</code>
|
||||
testString: 'assert((function(){ count = 0; cc(10);cc("J");cc("Q");cc("K");var out = cc("A"); if(out === "-5 Hold") {return true;} return false; })(), "Cards Sequence 10, J, Q, K, A should return <code>-5 Hold</code>");'
|
||||
testString: assert((function(){ count = 0; cc(10);cc('J');cc('Q');cc('K');var out = cc('A'); if(out === "-5 Hold") {return true;} return false; })());
|
||||
- text: '卡序列3,7,Q,8,A应返回<code>-1 Hold</code>'
|
||||
testString: 'assert((function(){ count = 0; cc(3);cc(7);cc("Q");cc(8);var out = cc("A"); if(out === "-1 Hold") {return true;} return false; })(), "Cards Sequence 3, 7, Q, 8, A should return <code>-1 Hold</code>");'
|
||||
testString: assert((function(){ count = 0; cc(3);cc(7);cc('Q');cc(8);var out = cc('A'); if(out === "-1 Hold") {return true;} return false; })());
|
||||
- text: 牌序列2,J, <code>1 Bet</code>应该返回<code>1 Bet</code>
|
||||
testString: 'assert((function(){ count = 0; cc(2);cc("J");cc(9);cc(2);var out = cc(7); if(out === "1 Bet") {return true;} return false; })(), "Cards Sequence 2, J, 9, 2, 7 should return <code>1 Bet</code>");'
|
||||
testString: assert((function(){ count = 0; cc(2);cc('J');cc(9);cc(2);var out = cc(7); if(out === "1 Bet") {return true;} return false; })());
|
||||
- text: 牌序列<code>1 Bet</code>应该返回<code>1 Bet</code>
|
||||
testString: 'assert((function(){ count = 0; cc(2);cc(2);var out = cc(10); if(out === "1 Bet") {return true;} return false; })(), "Cards Sequence 2, 2, 10 should return <code>1 Bet</code>");'
|
||||
testString: assert((function(){ count = 0; cc(2);cc(2);var out = cc(10); if(out === "1 Bet") {return true;} return false; })());
|
||||
- text: '卡序列3,2,A,10,K应返回<code>-1 Hold</code>'
|
||||
testString: 'assert((function(){ count = 0; cc(3);cc(2);cc("A");cc(10);var out = cc("K"); if(out === "-1 Hold") {return true;} return false; })(), "Cards Sequence 3, 2, A, 10, K should return <code>-1 Hold</code>");'
|
||||
testString: assert((function(){ count = 0; cc(3);cc(2);cc('A');cc(10);var out = cc('K'); if(out === "-1 Hold") {return true;} return false; })());
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 使用JavaScript创建十进制数
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myDecimal</code>应该是一个数字。
|
||||
testString: 'assert(typeof myDecimal === "number", "<code>myDecimal</code> should be a number.");'
|
||||
testString: assert(typeof myDecimal === "number");
|
||||
- text: <code>myDecimal</code>应该有一个小数点
|
||||
testString: 'assert(myDecimal % 1 != 0, "<code>myDecimal</code> should have a decimal point"); '
|
||||
testString: assert(myDecimal % 1 != 0);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,7 +18,7 @@ localeTitle: 声明JavaScript变量
|
||||
```yml
|
||||
tests:
|
||||
- text: 您应该使用<code>var</code>关键字声明<code>myName</code> ,以分号结尾
|
||||
testString: 'assert(/var\s+myName\s*;/.test(code), "You should declare <code>myName</code> with the <code>var</code> keyword, ending with a semicolon");'
|
||||
testString: assert(/var\s+myName\s*;/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 声明字符串变量
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myFirstName</code>应该是一个至少包含一个字符的字符串。
|
||||
testString: 'assert((function(){if(typeof myFirstName !== "undefined" && typeof myFirstName === "string" && myFirstName.length > 0){return true;}else{return false;}})(), "<code>myFirstName</code> should be a string with at least one character in it.");'
|
||||
testString: assert((function(){if(typeof myFirstName !== "undefined" && typeof myFirstName === "string" && myFirstName.length > 0){return true;}else{return false;}})());
|
||||
- text: <code>myLastName</code>应该是一个至少包含一个字符的字符串。
|
||||
testString: 'assert((function(){if(typeof myLastName !== "undefined" && typeof myLastName === "string" && myLastName.length > 0){return true;}else{return false;}})(), "<code>myLastName</code> should be a string with at least one character in it.");'
|
||||
testString: assert((function(){if(typeof myLastName !== "undefined" && typeof myLastName === "string" && myLastName.length > 0){return true;}else{return false;}})());
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,13 +18,13 @@ localeTitle: 使用JavaScript减少数字
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myVar</code>应该等于<code>10</code>
|
||||
testString: 'assert(myVar === 10, "<code>myVar</code> should equal <code>10</code>");'
|
||||
testString: assert(myVar === 10);
|
||||
- text: <code>myVar = myVar - 1;</code>应该改变
|
||||
testString: 'assert(/var\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code), "<code>myVar = myVar - 1;</code> should be changed");'
|
||||
testString: assert(/var\s*myVar\s*=\s*11;\s*\/*.*\s*([-]{2}\s*myVar|myVar\s*[-]{2});/.test(code));
|
||||
- text: 在<code>myVar</code>上使用<code>--</code>运算符
|
||||
testString: 'assert(/[-]{2}\s*myVar|myVar\s*[-]{2}/.test(code), "Use the <code>--</code> operator on <code>myVar</code>");'
|
||||
testString: assert(/[-]{2}\s*myVar|myVar\s*[-]{2}/.test(code));
|
||||
- text: 不要更改行上方的代码
|
||||
testString: 'assert(/var myVar = 11;/.test(code), "Do not change code above the line");'
|
||||
testString: assert(/var myVar = 11;/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 从JavaScript对象中删除属性
|
||||
```yml
|
||||
tests:
|
||||
- text: 从<code>myDog</code>删除属性<code>"tails"</code> 。
|
||||
testString: 'assert(typeof myDog === "object" && myDog.tails === undefined, "Delete the property <code>"tails"</code> from <code>myDog</code>.");'
|
||||
testString: assert(typeof myDog === "object" && myDog.tails === undefined);
|
||||
- text: 不要修改<code>myDog</code>设置
|
||||
testString: 'assert(code.match(/"tails": 1/g).length > 1, "Do not modify the <code>myDog</code> setup");'
|
||||
testString: 'assert(code.match(/"tails": 1/g).length > 1);'
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,11 +18,11 @@ localeTitle: 使用JavaScript将另一个十进制除以另一个
|
||||
```yml
|
||||
tests:
|
||||
- text: 变<code>quotient</code>应该等于<code>2.2</code>
|
||||
testString: 'assert(quotient === 2.2, "The variable <code>quotient</code> should equal <code>2.2</code>");'
|
||||
testString: assert(quotient === 2.2);
|
||||
- text: 您应该使用<code>/</code>运算符将4.4除以2
|
||||
testString: 'assert(/4\.40*\s*\/\s*2\.*0*/.test(code), "You should use the <code>/</code> operator to divide 4.4 by 2");'
|
||||
testString: assert(/4\.40*\s*\/\s*2\.*0*/.test(code));
|
||||
- text: 商数变量只应分配一次
|
||||
testString: 'assert(code.match(/quotient/g).length === 1, "The quotient variable should only be assigned once");'
|
||||
testString: assert(code.match(/quotient/g).length === 1);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 用JavaScript划分一个号码
|
||||
```yml
|
||||
tests:
|
||||
- text: 使变量<code>quotient</code>等于2。
|
||||
testString: 'assert(quotient === 2, "Make the variable <code>quotient</code> equal to 2.");'
|
||||
testString: assert(quotient === 2);
|
||||
- text: 使用<code>/</code>运算符
|
||||
testString: 'assert(/\d+\s*\/\s*\d+/.test(code), "Use the <code>/</code> operator");'
|
||||
testString: assert(/\d+\s*\/\s*\d+/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 逃避字符串中的字面引用
|
||||
```yml
|
||||
tests:
|
||||
- text: 您应该使用两个双引号( <code>"</code> )和四个转义双引号( <code>\"</code> )。
|
||||
testString: 'assert(code.match(/\\"/g).length === 4 && code.match(/[^\\]"/g).length === 2, "You should use two double quotes (<code>"</code>) and four escaped double quotes (<code>\"</code>).");'
|
||||
testString: assert(code.match(/\\"/g).length === 4 && code.match(/[^\\]"/g).length === 2);
|
||||
- text: 变量myStr应该包含字符串: <code>I am a "double quoted" string inside "double quotes".</code>
|
||||
testString: 'assert(myStr === "I am a \"double quoted\" string inside \"double quotes\".", "Variable myStr should contain the string: <code>I am a "double quoted" string inside "double quotes".</code>");'
|
||||
testString: 'assert(myStr === "I am a \"double quoted\" string inside \"double quotes\".");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,11 +18,11 @@ localeTitle: 在JavaScript中查找剩余内容
|
||||
```yml
|
||||
tests:
|
||||
- text: 应该初始化变量<code>remainder</code>
|
||||
testString: 'assert(/var\s+?remainder/.test(code), "The variable <code>remainder</code> should be initialized");'
|
||||
testString: assert(/var\s+?remainder/.test(code));
|
||||
- text: <code>remainder</code>的值应为<code>2</code>
|
||||
testString: 'assert(remainder === 2, "The value of <code>remainder</code> should be <code>2</code>");'
|
||||
testString: assert(remainder === 2);
|
||||
- text: 您应该使用<code>%</code>运算符
|
||||
testString: 'assert(/\s+?remainder\s*?=\s*?.*%.*;/.test(code), "You should use the <code>%</code> operator");'
|
||||
testString: assert(/\s+?remainder\s*?=\s*?.*%.*;/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,11 +18,11 @@ localeTitle: 使用JavaScript生成随机分数
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>randomFraction</code>应该返回一个随机数。
|
||||
testString: 'assert(typeof randomFraction() === "number", "<code>randomFraction</code> should return a random number.");'
|
||||
testString: assert(typeof randomFraction() === "number");
|
||||
- text: <code>randomFraction</code>返回的<code>randomFraction</code>应该是小数。
|
||||
testString: 'assert((randomFraction()+""). match(/\./g), "The number returned by <code>randomFraction</code> should be a decimal.");'
|
||||
testString: assert((randomFraction()+''). match(/\./g));
|
||||
- text: 您应该使用<code>Math.random</code>来生成随机十进制数。
|
||||
testString: 'assert(code.match(/Math\.random/g).length >= 0, "You should be using <code>Math.random</code> to generate the random decimal number.");'
|
||||
testString: assert(code.match(/Math\.random/g).length >= 0);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,13 +18,13 @@ localeTitle: 使用JavaScript生成随机整数
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>randomWholeNum</code>的结果应该是整数。
|
||||
testString: 'assert(typeof randomWholeNum() === "number" && (function(){var r = randomWholeNum();return Math.floor(r) === r;})(), "The result of <code>randomWholeNum</code> should be a whole number.");'
|
||||
testString: assert(typeof randomWholeNum() === "number" && (function(){var r = randomWholeNum();return Math.floor(r) === r;})());
|
||||
- text: 您应该使用<code>Math.random</code>来生成随机数。
|
||||
testString: 'assert(code.match(/Math.random/g).length > 1, "You should be using <code>Math.random</code> to generate a random number.");'
|
||||
testString: assert(code.match(/Math.random/g).length > 1);
|
||||
- text: 您应该将<code>Math.random</code>的结果乘以10,使其成为介于0和9之间的数字。
|
||||
testString: 'assert(code.match(/\s*?Math.random\s*?\(\s*?\)\s*?\*\s*?10[\D]\s*?/g) || code.match(/\s*?10\s*?\*\s*?Math.random\s*?\(\s*?\)\s*?/g), "You should have multiplied the result of <code>Math.random</code> by 10 to make it a number that is between zero and nine.");'
|
||||
testString: assert(code.match(/\s*?Math.random\s*?\(\s*?\)\s*?\*\s*?10[\D]\s*?/g) || code.match(/\s*?10\s*?\*\s*?Math.random\s*?\(\s*?\)\s*?/g));
|
||||
- text: 您应该使用<code>Math.floor</code>删除数字的小数部分。
|
||||
testString: 'assert(code.match(/Math.floor/g).length > 1, "You should use <code>Math.floor</code> to remove the decimal part of the number.");'
|
||||
testString: assert(code.match(/Math.floor/g).length > 1);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,13 +18,13 @@ localeTitle: 生成范围内的随机整数
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>randomRange</code>可以生成的最低随机数应该等于你的最小数量<code>myMin</code> 。
|
||||
testString: 'assert(calcMin === 5, "The lowest random number that can be generated by <code>randomRange</code> should be equal to your minimum number, <code>myMin</code>.");'
|
||||
testString: assert(calcMin === 5);
|
||||
- text: <code>randomRange</code>可以生成的最高随机数应该等于最大数量<code>myMax</code> 。
|
||||
testString: 'assert(calcMax === 15, "The highest random number that can be generated by <code>randomRange</code> should be equal to your maximum number, <code>myMax</code>.");'
|
||||
testString: assert(calcMax === 15);
|
||||
- text: <code>randomRange</code>生成的随机数应该是整数,而不是小数。
|
||||
testString: 'assert(randomRange(0,1) % 1 === 0 , "The random number generated by <code>randomRange</code> should be an integer, not a decimal.");'
|
||||
testString: assert(randomRange(0,1) % 1 === 0 );
|
||||
- text: <code>randomRange</code>应该同时使用<code>myMax</code>和<code>myMin</code> ,并在你的范围内返回一个随机数。
|
||||
testString: 'assert((function(){if(code.match(/myMax/g).length > 1 && code.match(/myMin/g).length > 2 && code.match(/Math.floor/g) && code.match(/Math.random/g)){return true;}else{return false;}})(), "<code>randomRange</code> should use both <code>myMax</code> and <code>myMin</code>, and return a random number in your range.");'
|
||||
testString: assert((function(){if(code.match(/myMax/g).length > 1 && code.match(/myMin/g).length > 2 && code.match(/Math.floor/g) && code.match(/Math.random/g)){return true;}else{return false;}})());
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,13 +18,13 @@ localeTitle: 全球范围和职能
|
||||
```yml
|
||||
tests:
|
||||
- text: 应该定义<code>myGlobal</code>
|
||||
testString: 'assert(typeof myGlobal != "undefined", "<code>myGlobal</code> should be defined");'
|
||||
testString: assert(typeof myGlobal != "undefined");
|
||||
- text: <code>myGlobal</code>的值应为<code>10</code>
|
||||
testString: 'assert(myGlobal === 10, "<code>myGlobal</code> should have a value of <code>10</code>");'
|
||||
testString: assert(myGlobal === 10);
|
||||
- text: 应使用<code>var</code>关键字声明<code>myGlobal</code>
|
||||
testString: 'assert(/var\s+myGlobal/.test(code), "<code>myGlobal</code> should be declared using the <code>var</code> keyword");'
|
||||
testString: assert(/var\s+myGlobal/.test(code));
|
||||
- text: <code>oopsGlobal</code>应该是一个全局变量,其值为<code>5</code>
|
||||
testString: 'assert(typeof oopsGlobal != "undefined" && oopsGlobal === 5, "<code>oopsGlobal</code> should be a global variable and have a value of <code>5</code>");'
|
||||
testString: assert(typeof oopsGlobal != "undefined" && oopsGlobal === 5);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,11 +18,11 @@ localeTitle: 功能中的全局与局部范围
|
||||
```yml
|
||||
tests:
|
||||
- text: 不要更改全局<code>outerWear</code>的值
|
||||
testString: 'assert(outerWear === "T-Shirt", "Do not change the value of the global <code>outerWear</code>");'
|
||||
testString: assert(outerWear === "T-Shirt");
|
||||
- text: <code>myOutfit</code>应该返回<code>"sweater"</code>
|
||||
testString: 'assert(myOutfit() === "sweater", "<code>myOutfit</code> should return <code>"sweater"</code>");'
|
||||
testString: assert(myOutfit() === "sweater");
|
||||
- text: 不要更改return语句
|
||||
testString: 'assert(/return outerWear/.test(code), "Do not change the return statement");'
|
||||
testString: assert(/return outerWear/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -19,27 +19,27 @@ localeTitle: 高尔夫码
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>golfScore(4, 1)</code>应该返回“Hole-in-one!”'
|
||||
testString: 'assert(golfScore(4, 1) === "Hole-in-one!", "<code>golfScore(4, 1)</code> should return "Hole-in-one!"");'
|
||||
testString: assert(golfScore(4, 1) === "Hole-in-one!");
|
||||
- text: '<code>golfScore(4, 2)</code>应该返回“Eagle”'
|
||||
testString: 'assert(golfScore(4, 2) === "Eagle", "<code>golfScore(4, 2)</code> should return "Eagle"");'
|
||||
testString: assert(golfScore(4, 2) === "Eagle");
|
||||
- text: '<code>golfScore(5, 2)</code>应该返回“Eagle”'
|
||||
testString: 'assert(golfScore(5, 2) === "Eagle", "<code>golfScore(5, 2)</code> should return "Eagle"");'
|
||||
testString: assert(golfScore(5, 2) === "Eagle");
|
||||
- text: '<code>golfScore(4, 3)</code>应该返回“Birdie”'
|
||||
testString: 'assert(golfScore(4, 3) === "Birdie", "<code>golfScore(4, 3)</code> should return "Birdie"");'
|
||||
testString: assert(golfScore(4, 3) === "Birdie");
|
||||
- text: '<code>golfScore(4, 4)</code>应该返回“Par”'
|
||||
testString: 'assert(golfScore(4, 4) === "Par", "<code>golfScore(4, 4)</code> should return "Par"");'
|
||||
testString: assert(golfScore(4, 4) === "Par");
|
||||
- text: '<code>golfScore(1, 1)</code>应该返回“Hole-in-one!”'
|
||||
testString: 'assert(golfScore(1, 1) === "Hole-in-one!", "<code>golfScore(1, 1)</code> should return "Hole-in-one!"");'
|
||||
testString: assert(golfScore(1, 1) === "Hole-in-one!");
|
||||
- text: '<code>golfScore(5, 5)</code>应该返回“Par”'
|
||||
testString: 'assert(golfScore(5, 5) === "Par", "<code>golfScore(5, 5)</code> should return "Par"");'
|
||||
testString: assert(golfScore(5, 5) === "Par");
|
||||
- text: '<code>golfScore(4, 5)</code>应该返回“Bogey”'
|
||||
testString: 'assert(golfScore(4, 5) === "Bogey", "<code>golfScore(4, 5)</code> should return "Bogey"");'
|
||||
testString: assert(golfScore(4, 5) === "Bogey");
|
||||
- text: '<code>golfScore(4, 6)</code>应该返回“Double Bogey”'
|
||||
testString: 'assert(golfScore(4, 6) === "Double Bogey", "<code>golfScore(4, 6)</code> should return "Double Bogey"");'
|
||||
testString: assert(golfScore(4, 6) === "Double Bogey");
|
||||
- text: '<code>golfScore(4, 7)</code>应该返回“Go Home!”'
|
||||
testString: 'assert(golfScore(4, 7) === "Go Home!", "<code>golfScore(4, 7)</code> should return "Go Home!"");'
|
||||
testString: assert(golfScore(4, 7) === "Go Home!");
|
||||
- text: '<code>golfScore(5, 9)</code>应该返回“Go Home!”'
|
||||
testString: 'assert(golfScore(5, 9) === "Go Home!", "<code>golfScore(5, 9)</code> should return "Go Home!"");'
|
||||
testString: assert(golfScore(5, 9) === "Go Home!");
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,13 +18,13 @@ localeTitle: 使用JavaScript增加数字
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myVar</code>应该等于<code>88</code>
|
||||
testString: 'assert(myVar === 88, "<code>myVar</code> should equal <code>88</code>");'
|
||||
testString: assert(myVar === 88);
|
||||
- text: <code>myVar = myVar + 1;</code>应该改变
|
||||
testString: 'assert(/var\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code), "<code>myVar = myVar + 1;</code> should be changed");'
|
||||
testString: assert(/var\s*myVar\s*=\s*87;\s*\/*.*\s*([+]{2}\s*myVar|myVar\s*[+]{2});/.test(code));
|
||||
- text: 使用<code>++</code>运算符
|
||||
testString: 'assert(/[+]{2}\s*myVar|myVar\s*[+]{2}/.test(code), "Use the <code>++</code> operator");'
|
||||
testString: assert(/[+]{2}\s*myVar|myVar\s*[+]{2}/.test(code));
|
||||
- text: 不要更改行上方的代码
|
||||
testString: 'assert(/var myVar = 87;/.test(code), "Do not change code above the line");'
|
||||
testString: assert(/var myVar = 87;/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,7 +18,7 @@ localeTitle: 使用赋值运算符初始化变量
|
||||
```yml
|
||||
tests:
|
||||
- text: 将<code>a</code>初始化为值<code>9</code>
|
||||
testString: 'assert(/var\s+a\s*=\s*9\s*/.test(code), "Initialize <code>a</code> to a value of <code>9</code>");'
|
||||
testString: assert(/var\s+a\s*=\s*9\s*/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,21 +18,21 @@ localeTitle: 如果声明引入Else
|
||||
```yml
|
||||
tests:
|
||||
- text: 你应该至少有两个<code>else</code>语句
|
||||
testString: 'assert(code.match(/else/g).length > 1, "You should have at least two <code>else</code> statements");'
|
||||
testString: assert(code.match(/else/g).length > 1);
|
||||
- text: 你应该至少有两个<code>if</code>语句
|
||||
testString: 'assert(code.match(/if/g).length > 1, "You should have at least two <code>if</code> statements");'
|
||||
testString: assert(code.match(/if/g).length > 1);
|
||||
- text: 您应该为每个条件关闭并打开花括号
|
||||
testString: 'assert(code.match(/if\s*\((.+)\)\s*\{[\s\S]+\}\s*else if\s*\((.+)\)\s*\{[\s\S]+\}\s*else\s*\{[\s\S]+\s*\}/), "You should have closing and opening curly braces for each condition in your if else statement");'
|
||||
testString: assert(code.match(/if\s*\((.+)\)\s*\{[\s\S]+\}\s*else if\s*\((.+)\)\s*\{[\s\S]+\}\s*else\s*\{[\s\S]+\s*\}/));
|
||||
- text: <code>testElseIf(0)</code>应返回“小于5”
|
||||
testString: 'assert(testElseIf(0) === "Smaller than 5", "<code>testElseIf(0)</code> should return "Smaller than 5"");'
|
||||
testString: assert(testElseIf(0) === "Smaller than 5");
|
||||
- text: <code>testElseIf(5)</code>应该返回“5到10之间”
|
||||
testString: 'assert(testElseIf(5) === "Between 5 and 10", "<code>testElseIf(5)</code> should return "Between 5 and 10"");'
|
||||
testString: assert(testElseIf(5) === "Between 5 and 10");
|
||||
- text: <code>testElseIf(7)</code>应返回“5到10之间”
|
||||
testString: 'assert(testElseIf(7) === "Between 5 and 10", "<code>testElseIf(7)</code> should return "Between 5 and 10"");'
|
||||
testString: assert(testElseIf(7) === "Between 5 and 10");
|
||||
- text: <code>testElseIf(10)</code>应返回“5到10之间”
|
||||
testString: 'assert(testElseIf(10) === "Between 5 and 10", "<code>testElseIf(10)</code> should return "Between 5 and 10"");'
|
||||
testString: assert(testElseIf(10) === "Between 5 and 10");
|
||||
- text: <code>testElseIf(12)</code>应返回“大于10”
|
||||
testString: 'assert(testElseIf(12) === "Greater than 10", "<code>testElseIf(12)</code> should return "Greater than 10"");'
|
||||
testString: assert(testElseIf(12) === "Greater than 10");
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,19 +18,19 @@ localeTitle: 介绍其他声明
|
||||
```yml
|
||||
tests:
|
||||
- text: 您应该只在编辑器中有一个<code>if</code>语句
|
||||
testString: 'assert(code.match(/if/g).length === 1, "You should only have one <code>if</code> statement in the editor");'
|
||||
testString: assert(code.match(/if/g).length === 1);
|
||||
- text: 你应该使用<code>else</code>语句
|
||||
testString: 'assert(/else/g.test(code), "You should use an <code>else</code> statement");'
|
||||
testString: assert(/else/g.test(code));
|
||||
- text: <code>testElse(4)</code>应返回“5或更小”
|
||||
testString: 'assert(testElse(4) === "5 or Smaller", "<code>testElse(4)</code> should return "5 or Smaller"");'
|
||||
testString: assert(testElse(4) === "5 or Smaller");
|
||||
- text: <code>testElse(5)</code>应返回“5或更小”
|
||||
testString: 'assert(testElse(5) === "5 or Smaller", "<code>testElse(5)</code> should return "5 or Smaller"");'
|
||||
testString: assert(testElse(5) === "5 or Smaller");
|
||||
- text: <code>testElse(6)</code>应该返回“大于5”
|
||||
testString: 'assert(testElse(6) === "Bigger than 5", "<code>testElse(6)</code> should return "Bigger than 5"");'
|
||||
testString: assert(testElse(6) === "Bigger than 5");
|
||||
- text: <code>testElse(10)</code>应该返回“大于5”
|
||||
testString: 'assert(testElse(10) === "Bigger than 5", "<code>testElse(10)</code> should return "Bigger than 5"");'
|
||||
testString: assert(testElse(10) === "Bigger than 5");
|
||||
- text: 请勿更改行上方或下方的代码。
|
||||
testString: 'assert(/var result = "";/.test(code) && /return result;/.test(code), "Do not change the code above or below the lines.");'
|
||||
testString: assert(/var result = "";/.test(code) && /return result;/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 使用For循环迭代奇数
|
||||
```yml
|
||||
tests:
|
||||
- text: 你应该为此使用<code>for</code>循环。
|
||||
testString: 'assert(code.match(/for\s*\(/g).length > 1, "You should be using a <code>for</code> loop for this.");'
|
||||
testString: assert(code.match(/for\s*\(/g).length > 1);
|
||||
- text: '<code>myArray</code>应该等于<code>[1,3,5,7,9]</code> 。'
|
||||
testString: 'assert.deepEqual(myArray, [1,3,5,7,9], "<code>myArray</code> should equal <code>[1,3,5,7,9]</code>.");'
|
||||
testString: assert.deepEqual(myArray, [1,3,5,7,9]);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,13 +18,13 @@ localeTitle: 使用For循环遍历数组
|
||||
```yml
|
||||
tests:
|
||||
- text: 应声明<code>total</code>并初始化为0
|
||||
testString: 'assert(code.match(/var.*?total\s*=\s*0.*?;/), "<code>total</code> should be declared and initialized to 0");'
|
||||
testString: assert(code.match(/(var|let|const)\s*?total\s*=\s*0.*?;?/));
|
||||
- text: <code>total</code>应该等于20
|
||||
testString: 'assert(total === 20, "<code>total</code> should equal 20");'
|
||||
testString: assert(total === 20);
|
||||
- text: 您应该使用<code>for</code>循环来遍历<code>myArr</code>
|
||||
testString: 'assert(code.match(/for\s*\(/g).length > 1 && code.match(/myArr\s*\[/), "You should use a <code>for</code> loop to iterate through <code>myArr</code>");'
|
||||
testString: assert(code.match(/for\s*\(/g).length > 1 && code.match(/myArr\s*\[/));
|
||||
- text: 不要直接将<code>total</code>设置为20
|
||||
testString: 'assert(!code.match(/total[\s\+\-]*=\s*(\d(?!\s*[;,])|[1-9])/g), "Do not set <code>total</code> to 20 directly");'
|
||||
testString: assert(!code.replace(/\s/g, '').match(/total[=+-]0*[1-9]+/gm));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,11 +18,11 @@ localeTitle: 使用JavaScript迭代...循环
|
||||
```yml
|
||||
tests:
|
||||
- text: 你应该使用<code>do...while</code>循环。
|
||||
testString: 'assert(code.match(/do/g), "You should be using a <code>do...while</code> loop for this.");'
|
||||
testString: assert(code.match(/do/g));
|
||||
- text: '<code>myArray</code>应该等于<code>[10]</code> 。'
|
||||
testString: 'assert.deepEqual(myArray, [10], "<code>myArray</code> should equal <code>[10]</code>.");'
|
||||
testString: assert.deepEqual(myArray, [10]);
|
||||
- text: <code>i</code>应该等于<code>11</code>
|
||||
testString: 'assert.deepEqual(i, 11, "<code>i</code> should equal <code>11</code>");'
|
||||
testString: assert.equal(i, 11);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 使用JavaScript迭代循环
|
||||
```yml
|
||||
tests:
|
||||
- text: 你应该为此使用<code>for</code>循环。
|
||||
testString: 'assert(code.match(/for\s*\(/g).length > 1, "You should be using a <code>for</code> loop for this.");'
|
||||
testString: assert(code.match(/for\s*\(/g).length > 1);
|
||||
- text: '<code>myArray</code>应该等于<code>[1,2,3,4,5]</code> 。'
|
||||
testString: 'assert.deepEqual(myArray, [1,2,3,4,5], "<code>myArray</code> should equal <code>[1,2,3,4,5]</code>.");'
|
||||
testString: assert.deepEqual(myArray, [1,2,3,4,5]);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 在循环时使用JavaScript进行迭代
|
||||
```yml
|
||||
tests:
|
||||
- text: 你应该使用<code>while</code>循环。
|
||||
testString: 'assert(code.match(/while/g), "You should be using a <code>while</code> loop for this.");'
|
||||
testString: assert(code.match(/while/g));
|
||||
- text: '<code>myArray</code>应该等于<code>[0,1,2,3,4]</code> 。'
|
||||
testString: 'assert.deepEqual(myArray, [0,1,2,3,4], "<code>myArray</code> should equal <code>[0,1,2,3,4]</code>.");'
|
||||
testString: assert.deepEqual(myArray, [5,4,3,2,1,0]);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 本地范围和功能
|
||||
```yml
|
||||
tests:
|
||||
- text: 没有全局<code>myVar</code>变量
|
||||
testString: 'assert(typeof myVar === "undefined", "No global <code>myVar</code> variable");'
|
||||
testString: assert(typeof myVar === 'undefined');
|
||||
- text: 添加本地<code>myVar</code>变量
|
||||
testString: 'assert(/var\s+myVar/.test(code), "Add a local <code>myVar</code> variable");'
|
||||
testString: assert(/function\s+myLocalScope\s*\(\s*\)\s*\{\s[\s\S]+\s*var\s*myVar\s*(\s*|=[\s\S]+)\s*;[\s\S]+}/.test(code));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,11 +18,11 @@ localeTitle: 如果其他陈述中的逻辑顺序
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>orderMyLogic(4)</code>应返回“小于5”
|
||||
testString: 'assert(orderMyLogic(4) === "Less than 5", "<code>orderMyLogic(4)</code> should return "Less than 5"");'
|
||||
testString: assert(orderMyLogic(4) === "Less than 5");
|
||||
- text: <code>orderMyLogic(6)</code>应该返回“少于10”
|
||||
testString: 'assert(orderMyLogic(6) === "Less than 10", "<code>orderMyLogic(6)</code> should return "Less than 10"");'
|
||||
testString: assert(orderMyLogic(6) === "Less than 10");
|
||||
- text: <code>orderMyLogic(11)</code>应该返回“大于或等于10”
|
||||
testString: 'assert(orderMyLogic(11) === "Greater than or equal to 10", "<code>orderMyLogic(11)</code> should return "Greater than or equal to 10"");'
|
||||
testString: assert(orderMyLogic(11) === "Greater than or equal to 10");
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,11 +18,11 @@ localeTitle: 使用pop()操作数组
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>myArray</code>应该只包含<code>[["John", 23]]</code> 。'
|
||||
testString: 'assert((function(d){if(d[0][0] == "John" && d[0][1] === 23 && d[1] == undefined){return true;}else{return false;}})(myArray), "<code>myArray</code> should only contain <code>[["John", 23]]</code>.");'
|
||||
testString: assert((function(d){if(d[0][0] == 'John' && d[0][1] === 23 && d[1] == undefined){return true;}else{return false;}})(myArray));
|
||||
- text: 在<code>myArray</code>上使用<code>pop()</code>
|
||||
testString: 'assert(/removedFromMyArray\s*=\s*myArray\s*.\s*pop\s*(\s*)/.test(code), "Use <code>pop()</code> on <code>myArray</code>");'
|
||||
testString: assert(/removedFromMyArray\s*=\s*myArray\s*.\s*pop\s*(\s*)/.test(code));
|
||||
- text: '<code>removedFromMyArray</code>应该只包含<code>["cat", 2]</code> 。'
|
||||
testString: 'assert((function(d){if(d[0] == "cat" && d[1] === 2 && d[2] == undefined){return true;}else{return false;}})(removedFromMyArray), "<code>removedFromMyArray</code> should only contain <code>["cat", 2]</code>.");'
|
||||
testString: assert((function(d){if(d[0] == 'cat' && d[1] === 2 && d[2] == undefined){return true;}else{return false;}})(removedFromMyArray));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,7 +18,7 @@ localeTitle: 用push()操纵数组
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>myArray</code>现在应该等于<code>[["John", 23], ["cat", 2], ["dog", 3]]</code> 。'
|
||||
testString: 'assert((function(d){if(d[2] != undefined && d[0][0] == "John" && d[0][1] === 23 && d[2][0] == "dog" && d[2][1] === 3 && d[2].length == 2){return true;}else{return false;}})(myArray), "<code>myArray</code> should now equal <code>[["John", 23], ["cat", 2], ["dog", 3]]</code>.");'
|
||||
testString: assert((function(d){if(d[2] != undefined && d[0][0] == 'John' && d[0][1] === 23 && d[2][0] == 'dog' && d[2][1] === 3 && d[2].length == 2){return true;}else{return false;}})(myArray));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 使用shift()操纵数组
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>myArray</code>现在应该等于<code>[["dog", 3]]</code> 。'
|
||||
testString: 'assert((function(d){if(d[0][0] == "dog" && d[0][1] === 3 && d[1] == undefined){return true;}else{return false;}})(myArray), "<code>myArray</code> should now equal <code>[["dog", 3]]</code>.");'
|
||||
testString: assert((function(d){if(d[0][0] == 'dog' && d[0][1] === 3 && d[1] == undefined){return true;}else{return false;}})(myArray));
|
||||
- text: '<code>removedFromMyArray</code>应该包含<code>["John", 23]</code> 。'
|
||||
testString: 'assert((function(d){if(d[0] == "John" && d[1] === 23 && typeof removedFromMyArray === "object"){return true;}else{return false;}})(removedFromMyArray), "<code>removedFromMyArray</code> should contain <code>["John", 23]</code>.");'
|
||||
testString: assert((function(d){if(d[0] == 'John' && d[1] === 23 && typeof removedFromMyArray === 'object'){return true;}else{return false;}})(removedFromMyArray));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,7 +18,7 @@ localeTitle: 使用unshift操作数组()
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>myArray</code>现在应该有[[“Paul”,35],[“dog”,3]]。'
|
||||
testString: 'assert((function(d){if(typeof d[0] === "object" && d[0][0] == "Paul" && d[0][1] === 35 && d[1][0] != undefined && d[1][0] == "dog" && d[1][1] != undefined && d[1][1] == 3){return true;}else{return false;}})(myArray), "<code>myArray</code> should now have [["Paul", 35], ["dog", 3]].");'
|
||||
testString: assert((function(d){if(typeof d[0] === "object" && d[0][0] == 'Paul' && d[0][1] === 35 && d[1][0] != undefined && d[1][0] == 'dog' && d[1][1] != undefined && d[1][1] == 3){return true;}else{return false;}})(myArray));
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,23 +18,23 @@ localeTitle: 操纵复杂对象
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>myMusic</code>应该是一个数组
|
||||
testString: 'assert(Array.isArray(myMusic), "<code>myMusic</code> should be an array");'
|
||||
testString: assert(Array.isArray(myMusic));
|
||||
- text: <code>myMusic</code>应该至少有两个元素
|
||||
testString: 'assert(myMusic.length > 1, "<code>myMusic</code> should have at least two elements");'
|
||||
testString: assert(myMusic.length > 1);
|
||||
- text: '<code>myMusic[1]</code>应该是一个对象'
|
||||
testString: 'assert(typeof myMusic[1] === "object", "<code>myMusic[1]</code> should be an object");'
|
||||
testString: assert(typeof myMusic[1] === 'object');
|
||||
- text: '<code>myMusic[1]</code>应该至少有4个属性'
|
||||
testString: 'assert(Object.keys(myMusic[1]).length > 3, "<code>myMusic[1]</code> should have at least 4 properties");'
|
||||
testString: assert(Object.keys(myMusic[1]).length > 3);
|
||||
- text: '<code>myMusic[1]</code>应该包含一个<code>artist</code>属性,它是一个字符串'
|
||||
testString: 'assert(myMusic[1].hasOwnProperty("artist") && typeof myMusic[1].artist === "string", "<code>myMusic[1]</code> should contain an <code>artist</code> property which is a string");'
|
||||
testString: assert(myMusic[1].hasOwnProperty('artist') && typeof myMusic[1].artist === 'string');
|
||||
- text: '<code>myMusic[1]</code>应该包含一个<code>title</code>属性,它是一个字符串'
|
||||
testString: 'assert(myMusic[1].hasOwnProperty("title") && typeof myMusic[1].title === "string", "<code>myMusic[1]</code> should contain a <code>title</code> property which is a string");'
|
||||
testString: assert(myMusic[1].hasOwnProperty('title') && typeof myMusic[1].title === 'string');
|
||||
- text: '<code>myMusic[1]</code>应该包含一个<code>release_year</code>属性,它是一个数字'
|
||||
testString: 'assert(myMusic[1].hasOwnProperty("release_year") && typeof myMusic[1].release_year === "number", "<code>myMusic[1]</code> should contain a <code>release_year</code> property which is a number");'
|
||||
testString: assert(myMusic[1].hasOwnProperty('release_year') && typeof myMusic[1].release_year === 'number');
|
||||
- text: '<code>myMusic[1]</code>应该包含一个<code>formats</code>属性,它是一个数组'
|
||||
testString: 'assert(myMusic[1].hasOwnProperty("formats") && Array.isArray(myMusic[1].formats), "<code>myMusic[1]</code> should contain a <code>formats</code> property which is an array");'
|
||||
testString: assert(myMusic[1].hasOwnProperty('formats') && Array.isArray(myMusic[1].formats));
|
||||
- text: <code>formats</code>应该是一个至少包含两个元素的字符串数组
|
||||
testString: 'assert(myMusic[1].formats.every(function(item) { return (typeof item === "string")}) && myMusic[1].formats.length > 1, "<code>formats</code> should be an array of strings with at least two elements");'
|
||||
testString: assert(myMusic[1].formats.every(function(item) { return (typeof item === "string")}) && myMusic[1].formats.length > 1);
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,9 +18,9 @@ localeTitle: 使用索引修改数组数据
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>myArray</code>现在应该是[45,64,99]。'
|
||||
testString: 'assert((function(){if(typeof myArray != "undefined" && myArray[0] == 45 && myArray[1] == 64 && myArray[2] == 99){return true;}else{return false;}})(), "<code>myArray</code> should now be [45,64,99].");'
|
||||
testString: assert((function(){if(typeof myArray != 'undefined' && myArray[0] == 45 && myArray[1] == 64 && myArray[2] == 99){return true;}else{return false;}})());
|
||||
- text: 您应该使用正确的索引来修改<code>myArray</code>的值。
|
||||
testString: 'assert((function(){if(code.match(/myArray\[0\]\s*=\s*/g)){return true;}else{return false;}})(), "You should be using correct index to modify the value in <code>myArray</code>.");'
|
||||
testString: assert((function(){if(code.match(/myArray\[0\]\s*=\s*/g)){return true;}else{return false;}})());
|
||||
|
||||
```
|
||||
|
||||
|
@ -18,27 +18,27 @@ localeTitle: 交换机语句中的多个相同选项
|
||||
```yml
|
||||
tests:
|
||||
- text: <code>sequentialSizes(1)</code>应返回“Low”
|
||||
testString: 'assert(sequentialSizes(1) === "Low", "<code>sequentialSizes(1)</code> should return "Low"");'
|
||||
testString: assert(sequentialSizes(1) === "Low");
|
||||
- text: <code>sequentialSizes(2)</code>应该返回“Low”
|
||||
testString: 'assert(sequentialSizes(2) === "Low", "<code>sequentialSizes(2)</code> should return "Low"");'
|
||||
testString: assert(sequentialSizes(2) === "Low");
|
||||
- text: <code>sequentialSizes(3)</code>应返回“Low”
|
||||
testString: 'assert(sequentialSizes(3) === "Low", "<code>sequentialSizes(3)</code> should return "Low"");'
|
||||
testString: assert(sequentialSizes(3) === "Low");
|
||||
- text: <code>sequentialSizes(4)</code>应返回“Mid”
|
||||
testString: 'assert(sequentialSizes(4) === "Mid", "<code>sequentialSizes(4)</code> should return "Mid"");'
|
||||
testString: assert(sequentialSizes(4) === "Mid");
|
||||
- text: <code>sequentialSizes(5)</code>应返回“Mid”
|
||||
testString: 'assert(sequentialSizes(5) === "Mid", "<code>sequentialSizes(5)</code> should return "Mid"");'
|
||||
testString: assert(sequentialSizes(5) === "Mid");
|
||||
- text: <code>sequentialSizes(6)</code>应返回“Mid”
|
||||
testString: 'assert(sequentialSizes(6) === "Mid", "<code>sequentialSizes(6)</code> should return "Mid"");'
|
||||
testString: assert(sequentialSizes(6) === "Mid");
|
||||
- text: <code>sequentialSizes(7)</code>应该返回“High”
|
||||
testString: 'assert(sequentialSizes(7) === "High", "<code>sequentialSizes(7)</code> should return "High"");'
|
||||
testString: assert(sequentialSizes(7) === "High");
|
||||
- text: <code>sequentialSizes(8)</code>应该返回“High”
|
||||
testString: 'assert(sequentialSizes(8) === "High", "<code>sequentialSizes(8)</code> should return "High"");'
|
||||
testString: assert(sequentialSizes(8) === "High");
|
||||
- text: <code>sequentialSizes(9)</code>应该返回“High”
|
||||
testString: 'assert(sequentialSizes(9) === "High", "<code>sequentialSizes(9)</code> should return "High"");'
|
||||
testString: assert(sequentialSizes(9) === "High");
|
||||
- text: 您不应该使用任何<code>if</code>或<code>else</code>语句
|
||||
testString: 'assert(!/else/g.test(code) || !/if/g.test(code), "You should not use any <code>if</code> or <code>else</code> statements");'
|
||||
testString: assert(!/else/g.test(code) || !/if/g.test(code));
|
||||
- text: 你应该有九个<code>case</code>陈述
|
||||
testString: 'assert(code.match(/case/g).length === 9, "You should have nine <code>case</code> statements");'
|
||||
testString: assert(code.match(/case/g).length === 9);
|
||||
|
||||
```
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user