A collection of extension methods for Arrays (some of these are only usable on arrays containing specific types)

Usage:

  • use this extension by adding this where you normally import modules: using zero.extensions.ArrayExt;
  • now you can use any of these functions on different arrays: [0, 1, 2, 3].get_random(); // 2
  • or use all of the extensions in this library by adding: using zero.extensions.Tools;

Static methods

statica_star (array:Array<Array<Int>>, options:AStarOptions):Array<IntPoint>

Runs A* algorithm over given array

Parameters:

array

input array

options

Returns:

Array

staticinlinecontains (array:Array<Dynamic>, value:Dynamic):Bool

Checks whether or not an array contains a value or object

 *  @param array input array
 *  @param value value to check
 *  @return	Bool

staticinlineexpand<T> (a:Array<T>, row_width:Int):Array<Array<T>>

Expands a 1D Array into a 2D Array

Parameters:

a

input array

row_width

how many values per row

Returns:

Array>

staticinlineflatten<T> (a:Array<Array<T>>):Array<T>

Flattens a 2D Array into a 1D Array

Parameters:

a

input array

Returns:

Array

staticflood_fill_1D (array:Array<Dynamic>, pos:Int, value:Dynamic):Void

Uses a flood-fill algorithm to change equal values contiguous to the input position to a new value

Parameters:

array

input array

pos

index position

value

new value

staticflood_fill_2D (array:Array<Array<Dynamic>>, x:Int, y:Int, value:Dynamic):Void

Uses a flood-fill algorithm to change equal values contiguous to the input coordinates to a new value

Parameters:

array

input array

x

x coordinate

y

y coordinate

value

new value

staticinlineget_random (array:Array<Dynamic>):Dynamic

Returns a random element from an array

 *  @param array input array
 *  @return	Dynamic

staticget_xy (array:Array<Array<Dynamic>>, x:Int, y:Int):Dynamic

get a value from a 2D array with coordinates

Parameters:

array

input array

x

x coordinate

y

y coordinate

Returns:

Dynamic

@:value({ max_value : -1 })staticheat_map (array:Array<Array<Dynamic>>, x:Int, y:Int, max_value:Int = -1):Array<Array<Int>>

Uses a flood-fill type algorithm to generate a heat map from the coordinates

Parameters:

array

input array

x

x coordinate

y

y coordinate

max_value

max heat value, -1 will find the max value based on the minimum result

Returns:

Array>

staticinlinelast (a:Array<Dynamic>):Dynamic

Returns the last element in an array

Parameters:

a

input array

Returns:

staticmedian (array:Array<Dynamic>):Dynamic

Return the value closest to the middle of the array

Parameters:

array

input array

Returns:

Dynamic

staticmerge<T> (a1:Array<T>, a2:Array<T>):Array<T>

Merges a second array (of the same type) into the first array

 *  @param a1 first array
 *  @param a2 second array
 *  @return Array<T>

staticset_xy (array:Array<Array<Dynamic>>, x:Int, y:Int, value:Dynamic):Void

set a value in a 2D array

Parameters:

array

input array

x

x coordinate

y

y coordinate

value

input value

staticshuffle<T> (array:Array<T>):Array<T>

shuffles an array in place and returns it @param array input array @return Array

staticinlinestrings_to_ints (array:Array<String>):Array<Int>

Converts an array of strings to an array of itegers

 *  @param array input array
 *  @return Array<Int>