It's an interesting challenge. Your answer isn't wrong per-se, as how you represent the empty array depends on the code that processes the value. I think your answer however may show a mix-up between the dimension of an array vs. the length of an array. A multidimensional array is nested according to the number of dimensions. So a two dimensional array with two rows and two columns might look like:
[[1,2],[3,4]]
The number of row and columns are the lengths of the arrays in each dimension. A three dimensional array with one element might look like
[[[1]]]
So when I see an array [[],[],[]] I see a two dimensional array, with a length of three in the first dimension. Make sense?
You can tell how many dimensions an array has by how many individual indices you need to access the values. let's add some values to the above array and access one:
constarr=[[1],[2],[3]]constvalue=arr[0][0]// value is 1
Notice that we need two indices to access the values. An array of three dimensions would be nested such that you need three indices. For example:
constarr=[[[1],[2]],[[3],[4]],[[5],[6]]]constvalue=arr[0][0][0]// value is 1
It's an interesting challenge. Your answer isn't wrong per-se, as how you represent the empty array depends on the code that processes the value. I think your answer however may show a mix-up between the dimension of an array vs. the length of an array. A multidimensional array is nested according to the number of dimensions. So a two dimensional array with two rows and two columns might look like:
The number of row and columns are the lengths of the arrays in each dimension. A three dimensional array with one element might look like
So when I see an array
[[],[],[]]
I see a two dimensional array, with a length of three in the first dimension. Make sense?Thank you Ryan!!! You teach me something new. i think here in this example: [[],[],[]] it's a 3d array?!
You can tell how many dimensions an array has by how many individual indices you need to access the values. let's add some values to the above array and access one:
Notice that we need two indices to access the values. An array of three dimensions would be nested such that you need three indices. For example:
Thanks so much Ryan, it makes a lot of sense now.