* fix(curriculum): tests quotes * fix(curriculum): fill seed-teardown * fix(curriculum): fix tests and remove unneeded seed-teardown
2.4 KiB
2.4 KiB
id, title, challengeType, guideUrl
id | title | challengeType | guideUrl |
---|---|---|---|
56592a60ddddeae28f7aa8e1 | Access Multi-Dimensional Arrays With Indexes | 1 | https://www.freecodecamp.org/guide/certificates/access-array-data-with-indexes |
Description
var arr = [Note
[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
There shouldn't be any spaces between the array name and the square brackets, like
array [0][0]
and even this array [0] [0]
is not allowed. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code.
Instructions
myArray
such that myData
is equal to 8
.
Tests
tests:
- text: <code>myData</code> should be equal to <code>8</code>.
testString: assert(myData === 8, '<code>myData</code> should be equal to <code>8</code>.');
- text: You should be using bracket notation to read the correct value from <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>.');
Challenge Seed
// 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];
After Test
if(typeof myArray !== "undefined"){(function(){return "myData: " + myData + " myArray: " + JSON.stringify(myArray);})();}
Solution
var myArray = [[1,2,3],[4,5,6], [7,8,9], [[10,11,12], 13, 14]];
var myData = myArray[2][1];