filter( fun2 );
trace(newLst);
}
}
96
Part I: The Core Language
The Array sort Method
The Array sort method is similar to the List filter method in that it takes a function as a parameter
and is used as a means to sort data. However, the function required by the Array sort method accepts
two parameters, both of which should have the same type as the items in the Array, as both parameters
will be two items from the Array. The return value of the function should be an Int of zero if the
properties to compare of the two items are equal, greater than zero if the first parameter is larger than
the second, and less than zero if the first parameter is less than the second. The items are then sorted
inside the original Array by passing each item and its neighbor to the function and repositioning them
appropriately. The items are rearranged inside the original Array, so the sort method returns Void .
class ArraySorting
{
public static function main()
{
var strArr = [???one???,???two???,???three???,???four???,???five???,???six???];
var fun1 = function( a : String, b : String ) : Int
{
var x : String = a.
Pages:
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220