Im not understanding this solution and am hoping for some insight/clarification. The solution is listed below.
Task: We have defined a variable, myNestedArray
, set equal to an array. Modify myNestedArray
, using any combination of strings, numbers, and booleans for data elements, so that it has exactly five levels of depth (remember, the outer-most array is level 1). Somewhere on the third level, include the string deep
, on the fourth level, include the string deeper
, and on the fifth level, include the string deepest
.
My confusion: Isnt myNestedArray already 5 levels deep before any modification? If so, then the only task is to add a string to 3 of those arrays, correct?
Why does the solution require inserting the string in an array for nyNestedArray[2]? As opposed to just adding the string via myNestedArray.push()?
And why does the solution require inserting the string in a nested array for myNestedArray[3]?
Etc for myNestedArray[4]…
As I’m writing this I think I may have had a light bulb moment… Before any modifications, myNestedArray is only 2 levels deep. So when I add [[]] to myNestedArray[4], that officially modifies myNestedArray to 5 levels deep, correct?
If thats correct, then why does the solution still require inserting nested arrays elsewhere? Instead of adding those strings via .push? Or even simpler, just hard code the string into the array?
let myNestedArray = [
// Only change code below this line
['unshift', false, 1, 2, 3, 'complex', 'nested'],
['loop', 'shift', 6, 7, 1000, 'method'],
['concat', false, true, 'spread', 'array', ['deep']],
['mutate', 1327.98, 'splice', 'slice', 'push', [['deeper']]],
['iterate', 1.3849, 7, '8.4876', 'arbitrary', 'depth', [[['deepest']]]]
// Only change code above this line
];
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0
Challenge: Basic Data Structures - Create complex multi-dimensional arrays
Link to the challenge: