Attributes | Name and Description |
---|---|
|
caplin.core.ArrayUtility()
This is a static class that never needs to be instantiated. |
Attributes | Name and Description |
---|---|
<static>
|
void
batchedForEach(Array data, Function itemProcessor, Object options)
Breaks down the processing of an array into a series of sequential asynchronous chunks. |
<static>
|
Boolean
inArray(Array pArray, Variant vValueToFind)
Return |
<static>
|
Array
intersect(Varargs One)
Creates an intersect of the supplied arrays. |
<static>
|
Boolean
isEqual(Array pArray1, Array pArray2)
Compares all elements of two arrays for equality. |
<static>
|
Array
removeItem(Array pArray, Variant vValueToRemove)
Removes the first example of the specified item in the specified array, or does nothing if the item is not found. |
<static>
|
Array
subtract(Varargs One)
Subtracts one or more arrays from the first array argument. |
<static>
|
Array
union(Varargs One)
Creates a union of the supplied arrays. |
<static>
|
Array
unique(Array pArray)
Returns a new array containing each item in the input array once. |
<static>
|
Array
uniquePrimitive(Array pArray)
Returns an array of the unique values contained within the input array. |
►
caplin.core.ArrayUtility()
This is a static class that never needs to be instantiated.
►
<static>
void
batchedForEach(Array data, Function itemProcessor, Object options)
Breaks down the processing of an array into a series of sequential asynchronous chunks.
The table below explains the accepted configuration options.
name | default | type | description |
---|---|---|---|
batchSize | 100 | Number | How many items should be be processed in one iteration. |
initialTimeoutMillis | 0 | Number | The number of milliseconds that the initial batch processing function call should be delayed by. |
iterationTimeoutMillis | 25 | Number | The number of milliseconds that each internally batched call should be delayed by. |
completionCallback | Function | A function that should be invoked once processing is complete. |
Array | data | The data to process. |
Function | itemProcessor | The function that should be invoked for each item in the given data
array. The method signature for this function should mirror that of the native Array#forEach method
i.e. (item, index, array). |
Object | options | (optional) The configuration options. |
►
<static>
Boolean
inArray(Array pArray, Variant vValueToFind)
Return true
if the input array contains the input value, false
otherwise.
Array | pArray | The Array to test for the presence of the input variant. May not be null or undefined. |
Variant | vValueToFind | Variant whose presence in the input array is to be tested. Works with null, undefined and NaN. |
true
if the specified value was found in the array, false
otherwise.
►
<static>
Array
intersect(Varargs One)
Creates an intersect of the supplied arrays.
This is a new array with new indexes that contain all the values that occur in all of the supplied arrays with no duplicates.
Varargs | One | or more array arguments. |
►
<static>
Boolean
isEqual(Array pArray1, Array pArray2)
Compares all elements of two arrays for equality.
If either array is null or undefined this function will return false.
Note: The comparison is performed with ===, so if nested arrays or maps are not identical, this function will return false even if they contain the exact same elements. However, this method will work with NaN, so arrays containing NaN can be equal to each other.
Array | pArray1 | The first Array to compare. |
Array | pArray2 | The second Array to compare. |
►
<static>
Array
removeItem(Array pArray, Variant vValueToRemove)
Removes the first example of the specified item in the specified array, or does nothing if the item is not found.
Since this method uses the built-in indexOf
which does work with NaN
, it will not work
if called with NaN and will throw an ArgumentError. If you need to remove NaN
, you'll have to loop
over the array and then splice it out.
Array | pArray | The Array from which to remove the specified item. May not be null or undefined. |
Variant | vValueToRemove | The Variant to be removed from the specified array. May not be NaN. |
►
<static>
Array
subtract(Varargs One)
Subtracts one or more arrays from the first array argument.
In other words, it creates a copy of the first array argument, and then removes all items that appear in any of the subsequent array arguments.
Varargs | One | or more array arguments. |
►
<static>
Array
union(Varargs One)
Creates a union of the supplied arrays. This is a new array with new indexes that contain all the values of the supplied arrays with no duplicates.
Varargs | One | or more array arguments. |
►
<static>
Array
unique(Array pArray)
Returns a new array containing each item in the input array once.
WARNING: This function is slow for big lists. Consider using uniquePrimitive if your use-case allows.
Array | pArray | The array to be examined for duplicate entries. May not be null or undefined. |
►
<static>
Array
uniquePrimitive(Array pArray)
Returns an array of the unique values contained within the input array.
WARNING: does not work on arrays containing non key-able values (e.g. objects, arrays), use only with arrays containing strings and/or numbers.
Will throw a TypeError if it finds an item in the array of type object.
Array | pArray | The array to be examined for duplicate entries. May not be null or undefined. |