An extension class for Array.

Available since

0.1.0

.

See also:

Static methods

staticat<T>(a:Array<T>, i:Int):Null<T>

Returns a value from an array at some position.

Parameters:

a

An array.

i

A position in the array. If i is negative or i > a.length-1, i will be wrapped.

Returns:

A value in a at position i.

staticinlinegetAll<T>(a:Array<T>, f:T ‑> Bool):Array<T>

Iterates through an array and returns all values in the array where f(value) == true.

Parameters:

a

The array to iterate through.

f

A function which will take a value in the array as parameter.

Returns:

An array containing the values in a where f(value) == true.

@:value({ asc : true })staticgetOne<T>(a:Array<T>, f:T ‑> Bool, asc:Bool = true):Null<T>

Iterates through an array and returns the first value in the array where f(value) == true.

Parameters:

a

The array to iterate through.

f

A function which will take a value in the array as parameter.

asc

true for ascendent iteration, false for descendent iteration.

Returns:

A value where f(value) == true. You get null if there is no such value, or if it is an actual value in the array.

@:value({ force : true, asc : true })staticinsertWhere<T>(a:Array<T>, v:T, f:T ‑> Bool, asc:Bool = true, force:Bool = true):Bool

Inserts a value in an array at a position where a condition is satisfied.

The value will be inserted at a position where for x being a value at that position, f(x) == true.

Parameters:

a

The array to iterate through.

v

A value to insert.

f

A function which will take a value in the array as parameter.

asc

true for ascendent iteration, false for descendent iteration.

force

If true and there is no value in the array where f(x) == true, v is added to the array anyway. The value will be added at the end if asc == true, otherwise it is added at the start.

Returns:

true if the value was inserted, false otherwise.

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

Returns the last value in an array.

staticquickSort<T>(a:Array<T>, condition:(T, T) ‑> Bool):Void

An insertion sort algorithm, which is a fast algorithm for nearly sorted arrays.

Example: [4,6,2,3,1].quicksort((a,b) -> a < b) results in [1,2,3,4,6].

Parameters:

a

An array to be sorted.

condition

A function where condition(a,b) returns true if a < b, false otherwise.

@:value({ asc : true })staticremoveIf<T>(a:Array<T>, f:T ‑> Bool, asc:Bool = true):T

Iterates through an array and removes the first value in the array where f(value) == true.

Parameters:

a

The array to iterate through.

f

A function which will take a value in the array as parameter.

asc

true for ascendent iteration, false for descendent iteration.

Returns:

The value that was removed, null if nothing was removed.

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

Removes multiple values from an array.

Ex: removeValues([a,b,a,b,a],[a,a])) removes the value a twice from the first array, resulting to [b,b,a].

Parameters:

a1

The array to remove values from.

a2

An array containing values to remove from a1.

Returns:

a1.