HELP ME!Create complex multi-dimensional arrays

Tell us what’s happening:

Your code so far


let myNestedArray = [
  // change code below this line
  ['unshift', false, 1, 2, 3, 'complex', 'nested'
   [['deep'],[['deeper'],[['deepest']]]]
  ],
  ['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']
  // change code above this line
];

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/create-complex-multi-dimensional-arrays

Okay, so the code you’re given looks like:

let myNestedArray = [
  // 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']
  // change code above this line
];

Now bear in mind, at the outermost layer:

let myNestedArray = [...];

We already have an Array one layer deep. The next step to examine is the given code: each member of that array is a SECOND array, which is a second layer deep. So, before you even begin, you’re already two layers in!

Now, you’re adding deep, deeper, and deepest into that first element of the myNestedArray, and that works fine and WILL pass. But notice: between 'nested` and your added arrays, you’re missing a comma. That’s to start.

Next, you’re adding an array to that element, which is exactly right – but that array is at the THIRD level. So rather than wrapping deep in ANOTHER array and making it fourth level, simply make the first member of your array the string 'deep'. The same applies to each layer deeper – by wrapping the string in an array each time, it is one layer too deep.

The string that might do what you want is in the spoiler below:

  ['unshift', false, 1, 2, 3, 'complex', 'nested',
   ['deep',['deeper',['deepest']]]
  ],
  // ...continue other arrays here.
2 Likes

OMG thank you so much!