Prev | Current Page 115 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

. . you get the picture.
To better understand multidimensional Arrays, it helps to imagine them when applied to numbers. For
example, a thousand contains ten hundreds, hundreds contain ten tens, and ten contains ten units. You
could put this in an Array format by placing each of the four numerical groups into Arrays of their own,
like this:
var thousandths : Array < Int > = [0,1,2,3,4,5,6,7,8,9];
var hundredths : Array < Int > = [0,1,2,3,4,5,6,7,8,9];
var tens : Array < Int > = [0,1,2,3,4,5,6,7,8,9];
var units : Array < Int > = [0,1,2,3,4,5,6,7,8,9];
Part I: The Core Language
46
The problem with this method is that the groups held in each of the arrays are not joined. You only have
one of each Array type, while in theory, you should have ten thousandths Arrays, one hundred
hundredths Arrays, one thousand tens Arrays, and ten thousand units Arrays. What ??™ s more, each of
the Arrays should be linked to the relevant items in the parent Arrays.
To resolve this issue, you can create Arrays of Arrays by specifying the type of a parent Array as an
Array, and repeat this for each child Array in the hierarchy:
var numbers : Array < Array < Array < Array < Int > > > > ;
Once this is done, you need to instantiate each of the Arrays in the hierarchy:
numbers = new Array();
for ( a = 0.


Pages:
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127