* 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>
1.6 KiB
1.6 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
56592a60ddddeae28f7aa8e1 | 使用索引访问多维数组 | 1 | https://scrimba.com/c/ckND4Cq | 16159 | access-multi-dimensional-arrays-with-indexes |
--description--
可以把 多维 数组看作成是一个 数组中的数组。当使用方括号去访问数组的时候,第一个[index]
访问的是第 N 个子数组,第二个[index]
访问的是第 N 个子数组的第N个元素。
示例
var arr = [
[1,2,3],
[4,5,6],
[7,8,9],
[[10,11,12], 13, 14]
];
arr[3]; // equals [[10,11,12], 13, 14]
arr[3][0]; // equals [10,11,12]
arr[3][0][1]; // equals 11
提示
数组名称和方括号之间不应该有任何空格,如array [0][0]
,甚至array [0][0]
,都是不正确的。尽管 JavaScript 能够处理,但可能会让看你代码的其他程序员感到困惑。
--instructions--
使用索引从myArray
选择一个元素,使得myData
的值为8
。
--hints--
myData
应该等于8
。
assert(myData === 8);
你应该使用方括号从myArray
中取值。
assert(
/myArray\[2\]\[1\]/g.test(code) &&
!/myData\s*=\s*(?:.*[-+*/%]|\d)/g.test(code)
);
--seed--
--after-user-code--
if(typeof myArray !== "undefined"){(function(){return "myData: " + myData + " myArray: " + JSON.stringify(myArray);})();}
--seed-contents--
// Setup
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];
// Only change code below this line
var myData = myArray[0][0];
--solutions--
var myArray = [[1,2,3],[4,5,6], [7,8,9], [[10,11,12], 13, 14]];
var myData = myArray[2][1];