Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

1.8 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
56bbb991ad1ed5201cd392ca 通过索引访问数组中的数据 1 https://scrimba.com/c/cBZQbTz 16158 access-array-data-with-indexes

--description--

我们可以使用索引 indexes 来访问数组中的数据。

数组索引与字符串索引一样使用中括号,但字符串索引得到的是一个字符,而数组索引得到的是一个元素。数组索引与字符串索引一样是从 0 开始的,所以数组中第一个元素的索引编号是 0。
示例

var array = [50,60,70];
array[0]; // equals 50
var data = array[1];  // equals 60

提示
数组名称和方括号之间不应有任何空格,如array [0]尽管 JavaScript 能够正确处理,但可能会让看你代码的其他程序员感到困惑

--instructions--

创建一个名为myData的变量,并把myArray的第一个索引上的值赋给它。

--hints--

变量myData的值应该等于myArray的第一个值。

assert(
  (function () {
    if (
      typeof myArray !== 'undefined' &&
      typeof myData !== 'undefined' &&
      myArray[0] === myData
    ) {
      return true;
    } else {
      return false;
    }
  })()
);

应使用方括号访问变量myArray中的数据。

assert(
  (function () {
    if (code.match(/\s*=\s*myArray\[0\]/g)) {
      return true;
    } else {
      return false;
    }
  })()
);

--seed--

--after-user-code--

if(typeof myArray !== "undefined" && typeof myData !== "undefined"){(function(y,z){return 'myArray = ' + JSON.stringify(y) + ', myData = ' + JSON.stringify(z);})(myArray, myData);}

--seed-contents--

// Setup
var myArray = [50,60,70];

// Only change code below this line

--solutions--

var myArray = [50,60,70];
var myData = myArray[0];