Prev | Current Page 113 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

You have to admit that it is often confusing to discern
the differences between the slice and splice methods. The two together sound like some gory horror
Chapter 3: Learning the Basics
45
movie, which is what you will be left with if you use splice when you meant to preserve the data in
your Array.
There is one difference between these two methods, however, which may sometimes raise a compiler
error if you happened to use one over the other by mistake, but will at least help you to mentally
differentiate the two methods. Whereas splice requires that you pass the length of the chunk of data to
remove as the second parameter, slice requires that the second parameter specify the location of the
end of the chunk you want to copy. This ending location is not included in the copied chunk of the Array.
Like splice , you can opt to use a negative value as the starting location for your chunk, but you can
also use a negative value for the end of the chunk. Remember, though, that the starting location must
exist before the end location:
var arrayCpy : Array < Int > = myArray.


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