Is there a trick or technique to reading/seeing the depth of a multidimensional array?
I’ve completed the challenge, but I can’t help but be blinded by all the open/close brackets in relation to a multidimensional array.
As you can see from my example I’ve used comments to try and make sense of the code as I go, in this way I can see a pattern start to develop the deeper we go (the indentation), but I wouldn’t be able to look at this in a month and just know that [“deeper”] is 5 levels down without it.
Just curious and figured I’d ask as I go.
Edit: Before hitting submit, I’ve just realised that if I count the open brackets from the outer array inwards, (the outer array being equal to 1) my nested array then sits X levels deep. Pattern found!!
But posting anyway if this helps anyone else.
Your code so far
let myNestedArray = [ // Only change code below this line // 2 levels deep ['unshift', false, 1, 2, 3, 'complex', 'nested'], // 3 levels deep [ ['loop', 'shift', 6, 7, 1000, 'method'], ["deep"] ], // 4 levels deep [ [ ['concat', false, true, 'spread', 'array'], ["deeper"] ] ], // 5 levels deep [ [ [ ['mutate', 1327.98, 'splice', 'slice', 'push'], ['iterate', 1.3849, 7, '8.4876', 'arbitrary', 'depth'], ["deepest"] ] ] ] // Only change code above this line ];
Your browser information:
User Agent is:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15.
Challenge: Create complex multi-dimensional arrays
Link to the challenge: