@@ -7,22 +7,28 @@ using Math;
77
88/**
99 * A collection of extension methods for Arrays (some of these are only usable on arrays containing specific types)
10+ *
11+ * **Usage:**
12+ *
13+ * - use this extension by adding this where you normally import modules: `using zero.extensions.ArrayExt;`
14+ * - now you can use any of these functions on different arrays: `[0, 1, 2, 3].get_random(); // 2`
15+ * - or use all of the extensions in this library by adding: `using zero.extensions.Tools;`
1016 */
1117class ArrayExt
1218{
1319
1420 /**
1521 * Converts an array of strings to an array of itegers
16- * @param array input array
17- * @return Array<Int>
22+ * @param array input array
23+ * @return Array<Int>
1824 */
1925 public static inline function strings_to_ints(array:Array<String>):Array<Int> return [for (s in array) Std.parseInt(s)];
2026
2127 /**
2228 * Checks whether or not an array contains a value or object
23- * @param array input array
24- * @param value value to check
25- * @return Bool
29+ * @param array input array
30+ * @param value value to check
31+ * @return Bool
2632 */
2733 public static inline function contains(array:Array<Dynamic>, value:Dynamic):Bool return array.indexOf(value) >= 0;
2834
@@ -35,15 +41,15 @@ class ArrayExt
3541
3642 /**
3743 * Returns a random element from an array
38- * @param array input array
39- * @return Dynamic
44+ * @param array input array
45+ * @return Dynamic
4046 */
4147 public static inline function get_random(array:Array<Dynamic>):Dynamic return array[array.length.get_random().to_int()];
4248
4349 /**
4450 * shuffles an array in place and returns it
45- * @param array input array
46- * @return Array<T>
51+ * @param array input array
52+ * @return Array<T>
4753 */
4854 public static function shuffle<T>(array:Array<T>):Array<T>
4955 {
@@ -60,9 +66,9 @@ class ArrayExt
6066
6167 /**
6268 * Merges a second array (of the same type) into the first array
63- * @param a1 first array
64- * @param a2 second array
65- * @return Array<T>
69+ * @param a1 first array
70+ * @param a2 second array
71+ * @return Array<T>
6672 */
6773 public static function merge<T>(a1:Array<T>, a2:Array<T>):Array<T>
6874 {
@@ -97,9 +103,9 @@ class ArrayExt
97103 /**
98104 * Uses a flood-fill algorithm to change equal values contiguous to the input coordinates to a new value
99105 * @param array input array
100- * @param x x coordinate
101- * @param y y coordinate
102- * @param value new value
106+ * @param x x coordinate
107+ * @param y y coordinate
108+ * @param value new value
103109 */
104110 public static function flood_fill_2D(array:Array<Array<Dynamic>>, x:Int, y:Int, value:Dynamic)
105111 {
@@ -121,9 +127,9 @@ class ArrayExt
121127
122128 /**
123129 * Uses a flood-fill algorithm to change equal values contiguous to the input position to a new value
124- * @param array input array
125- * @param pos index position
126- * @param value new value
130+ * @param array input array
131+ * @param pos index position
132+ * @param value new value
127133 */
128134 public static function flood_fill_1D(array:Array<Dynamic>, pos:Int, value:Dynamic)
129135 {
@@ -143,10 +149,10 @@ class ArrayExt
143149
144150 /**
145151 * Uses a flood-fill type algorithm to generate a heat map from the coordinates
146- * @param array input array
147- * @param x x coordinate
148- * @param y y coordinate
149- * @param max_value max heat value, -1 will find the max value based on the minimum result
152+ * @param array input array
153+ * @param x x coordinate
154+ * @param y y coordinate
155+ * @param max_value max heat value, -1 will find the max value based on the minimum result
150156 * @return Array<Array<Int>>
151157 */
152158 public static function heat_map(array:Array<Array<Dynamic>>, x:Int, y:Int, max_value:Int = -1):Array<Array<Int>>
@@ -178,9 +184,9 @@ class ArrayExt
178184
179185 /**
180186 * get a value from a 2D array with coordinates
181- * @param array input array
182- * @param x x coordinate
183- * @param y y coordinate
187+ * @param array input array
188+ * @param x x coordinate
189+ * @param y y coordinate
184190 * @return Dynamic
185191 */
186192 public static function get_xy(array:Array<Array<Dynamic>>, x:Int, y:Int):Dynamic
@@ -192,10 +198,10 @@ class ArrayExt
192198
193199 /**
194200 * set a value in a 2D array
195- * @param array input array
196- * @param x x coordinate
197- * @param y y coordinate
198- * @param value input value
201+ * @param array input array
202+ * @param x x coordinate
203+ * @param y y coordinate
204+ * @param value input value
199205 */
200206 public static function set_xy(array:Array<Array<Dynamic>>, x:Int, y:Int, value:Dynamic)
201207 {
0 commit comments