Basic Data Structures - Create complex multi-dimensional arrays

I don’t like how the tutorials make no effort to explain the formatting of most code, because for me this is the bit which is always hardest to understand

let nestedArray = [
  ['deep'],
  [
    ['deeper'], ['deeper'] 
  ],
  [
    [
      ['deepest'], ['deepest']
    ],
    [
      [
        ['deepest-est?']
      ]
    ]
  ]
];

The number of brackets in this example case makes no sense to me. Why are they like this? Its hard to remember the formatting if I dont understand the logic behind it

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'],
  ['mutate', 1327.98, 'splice', 'slice', 'push'],
  ['iterate', 1.3849, 7, '8.4876', 'arbitrary', 'depth']
  // Only change code above this line
];

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63

Challenge: Basic Data Structures - Create complex multi-dimensional arrays

Link to the challenge:

What exactly makes no sense for you in the example?

There is one open bracket between deep and deeper, then there’s 2 between that and the next string, then there’s two again between that and the final string (I’d expect it to be three if it’s increasing by one with each level). What’s the logic behind the number of open brackets

Relative number of brackets can be various, depending on which elements are under consideration.

The overall depth is counted to the most outer array, and these brackets should be then considered

[                          // 1
  ['deep'], [...], [...]   // 2
]
[                               // 1
  [...], 
  [                             // 2
    ['deeper'], ['deeper']      // 3
  ], 
  [...] 
]
[                                 // 1
  [...], 
  [...], 
  [                               // 2
    [                             // 3
      ['deepest'], ['deepest']    // 4
    ], 
    [...]
  ] 
]
[                           // 1
  [...], 
  [...], 
  [                         // 2
    [...], 
    [                       // 3
      [                     // 4
        ['deepest-est?']    // 5
      ]
    ]
  ]
]

Thank you sir

uhdiuuowdaw

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.