Construct a new empty SortedArray, using the default comparator and equality functions.
Construct a new SortedArray with the given length.
Construct a new empty SortedArray, optionally specifying a custom comparator function or a custom equality function.
The SortedArray implementation assumes that any values a
and b
for which equalityFunc(a, b) === true
,
it is also the case that compareFunc(a, b) === 0
.
Optional
compareFunc: SortedArrayComparatorFunction<T>A custom comparator function, to use instead of SortedArray.DefaultComparatorFunction. The comparator function determines the sort order of items in the array.
Optional
equalityFunc: SortedArrayEqualityFunction<T>A custom equality function, to use instead of SortedArray.DefaultEqualityFunction.
Construct a new SortedArray from the given items, which will
be sorted using the Array sort
function.
This is not guaranteed to be stable in all cases. See:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#sort_stability
The SortedArray implementation assumes that any values a
and b
for which equalityFunc(a, b) === true
,
it is also the case that compareFunc(a, b) === 0
.
An iterable of items to initially insert into the constructed SortedArray.
Optional
compareFunc: SortedArrayComparatorFunction<T>A custom comparator function, to use instead of SortedArray.DefaultComparatorFunction. The comparator function determines the sort order of items in the array.
Optional
equalityFunc: SortedArrayEqualityFunction<T>A custom equality function, to use instead of SortedArray.DefaultEqualityFunction.
Readonly
[unscopables]Is an object whose properties have the value 'true' when they will be absent when used in a 'with' statement.
Optional
Readonly
[unscopables]?: booleanIs an object whose properties have the value 'true' when they will be absent when used in a 'with' statement.
Optional
length?: booleanGets or sets the length of the array. This is a number one higher than the highest index in the array.
Comparator function used by the SortedArray.
Equality function used by the SortedArray.
Gets or sets the length of the array. This is a number one higher than the highest index in the array.
May refer to a reversed version of the SortedArray's comparator function.
Static
Readonly
[species]Get a new array with the values in this array concatenated with any number of other arrays.
This method is overridden to ensure that a normal Array is returned, instead of a SortedArray. It does not otherwise change the method's behavior.
Rest
...items: (T | ConcatArray<T>)[]Arrays to concatenate.
a new array containing the concatenated items.
Returns the this object after copying a section of the array identified by start and end to the same array starting at position target
If target is negative, it is treated as length+target where length is the length of the array.
If start is negative, it is treated as length+start. If end is negative, it is treated as length+end.
Optional
end: numberIf not specified, length of the this object is used as its default value.
Determines whether all the members of an array satisfy the specified test.
A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.
Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Determines whether all the members of an array satisfy the specified test.
A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.
Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Changes all array elements from start
to end
index to a static value
and returns the modified array
value to fill array section with
Optional
start: numberindex to start filling the array at. If start is negative, it is treated as length+start where length is the length of the array.
Optional
end: numberindex to stop filling the array at. If end is negative, it is treated as length+end.
Get a new SortedArray containing only those items which satisfy a given predicate function.
Optional
thisArg: Thisa new SortedArray containing only those values which satisfied the predicate function.
predicate A callback function which is invoked for each item in the array. The returned array will contain only those items for which the callback returned a truthy value.
thisArg An optional this
argument which the predicate
function should be called with.
Returns the value of the first element in the array where predicate is true, and undefined otherwise.
find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns undefined.
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.
Optional
thisArg: anyReturns the index of the first element in the array where predicate is true, and -1 otherwise.
find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1.
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.
Returns the first index at which a new value could be inserted into the array and maintain its sort order. This index will be before any other values with an equivalent sort order, if there are any such values in the array.
The value to check for insertion index.
Optional
fromIndex: numberStart comparing items at this index, inclusive.
Defaults to 0
, i.e. the beginning of the array.
Optional
endIndex: numberStop comparing items at this index, exclusive. Defaults to the length of the array.
The first valid insertion index for a new value.
Get a new array with sub-array items concatenated into it recursively, up to the specified depth.
This method is overridden to ensure that a normal Array is returned, instead of a SortedArray. It does not otherwise change the method's behavior.
Optional
depth: DepthHow deep a nested array structure should be flattened.
Defaults to 1
.
a new array containing the flattened items.
Get a new array formed by applying a given transformation callback function to each item in the array, and then flattening the result by one level.
This method is overridden to ensure that a normal Array is returned, instead of a SortedArray. It does not otherwise change the method's behavior.
A transformation callback function to be invoked for each item in the array. It should return an array containing new items for the new array, or a single non-array value to be added to the new array.
Optional
thisArg: Thisa new array containing the mapped and flattened items.
Performs the specified action for each element in an array.
A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
Optional
thisArg: anyAn object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
Get all equal values in the array and return them as a new SortedArray.
Equality is determined using the SortedArray's equality function, which is SortedArray.DefaultEqualityFunction when not otherwise specified.
Return values in the array that are equal to this one.
the equivalent elements as a new SortedArray.
Remove all equal values from the array and return those removed values as a new SortedArray.
Equality is determined using the SortedArray's equality function, which is SortedArray.DefaultEqualityFunction when not otherwise specified.
Remove the last item in the array that is equal to this input value.
the removed elements as a new SortedArray.
Check whether any item in the array is equal to the given value.
Equality is determined using the SortedArray's equality function, which is SortedArray.DefaultEqualityFunction when not otherwise specified.
Check whether there is any value in the array that is equal to this one.
Optional
fromIndex: numberStart looking for items at this index, inclusive.
Defaults to 0
, i.e. the beginning of the array.
true
if an equal item was found in the array, or false
if not.
Get the index of the first item in the array that is equal to
the given value, or -1
if there is no equal item in the array.
Equality is determined using the SortedArray's equality function, which is SortedArray.DefaultEqualityFunction when not otherwise specified.
Find the first index of a value in the array that is equal to this one.
Optional
fromIndex: numberStart looking for items at this index, inclusive.
Defaults to 0
, i.e. the beginning of the array.
the index of the first equal item, or -1
if no equal
item was found.
Get the index of the first item in the array that is equal to
the given value, or -1
if there is no equal item in the array.
Equality is determined using the SortedArray's equality function, which is SortedArray.DefaultEqualityFunction when not otherwise specified.
Find the first index of a value in the array that is equal to this one.
Optional
fromIndex: numberStart looking for items at this index, inclusive.
Defaults to 0
, i.e. the beginning of the array.
Optional
endIndex: numberStop looking for items at this index, exclusive. Defaults to the length of the array.
the index of the first equal item, or -1
if no equal
item was found.
Insert an iterable of assumed-sorted values into the array.
This should typically be more efficient than calling SortedArray.insert in a loop.
An iterable of values to be sorted into the array, which are already sorted according to this SortedArray's same comparator.
The new length of the array.
TypeError if the input was not iterable.
Adds all the elements of an array into a string, separated by the specified separator string.
Optional
separator: stringA string used to separate one element of the array from the next in the resulting string. If omitted, the array elements are separated with a comma.
Get the index of the last item in the array that is equal to
the given value, or -1
if there is no equal item in the array.
Equality is determined using the SortedArray's equality function, which is SortedArray.DefaultEqualityFunction when not otherwise specified.
Note that the behavior of this method differs from the normal
Array lastIndexOf
method in that passing undefined
explicitly
as the endIndex
argument is treated the same as omitting that
argument, instead of coercing the value to 0
.
Find the last index of a value in the array that is equal to this one.
Optional
endIndex: numberStop looking for items at this index. Defaults to the end of the array.
the index of the last equal item, or -1
if no equal
item was found.
Get the index of the last item in the array that is equal to
the given value, or -1
if there is no equal item in the array.
Equality is determined using the SortedArray's equality function, which is SortedArray.DefaultEqualityFunction when not otherwise specified.
Find the last index of a value in the array that is equal to this one.
Optional
fromIndex: numberStart looking for items at this index, inclusive.
Defaults to 0
, i.e. the beginning of the array.
Optional
endIndex: numberStop looking for items at this index, exclusive. Defaults to the length of the array.
the index of the last equal item, or -1
if no equal
item was found.
Returns the last index at which a new value could be inserted into the array and maintain its sort order. This index will be after any other values with an equivalent sort order, if there are any such values in the array.
The value to check for insertion index.
Optional
fromIndex: numberStart comparing items at this index, inclusive.
Defaults to 0
, i.e. the beginning of the array.
Optional
endIndex: numberStop comparing items at this index, exclusive. Defaults to the length of the array.
The last valid insertion index for a new value.
Get a new array populated with the results of calling a transformation callback function on every item in this array.
This method is overridden to ensure that a normal Array is returned, instead of a SortedArray. It does not otherwise change the method's behavior.
A transformation callback function to be invoked for each item in the array. Its return value is added as a single item in the new array.
Optional
thisArg: Thisa new array containing the values returned by calls to the transformation function.
Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
Remove the first equal value from the array.
Equality is determined using the SortedArray's equality function, which is SortedArray.DefaultEqualityFunction when not otherwise specified.
Remove the first item in the array that is equal to this input value.
true
if a matching element was found and removed,
or false
if no matching element was found.
Remove all equal values from the array.
Equality is determined using the SortedArray's equality function, which is SortedArray.DefaultEqualityFunction when not otherwise specified.
Remove all items in the array that are equal to this input value.
the number of removed array items.
Remove the last equal value from the array.
Equality is determined using the SortedArray's equality function, which is SortedArray.DefaultEqualityFunction when not otherwise specified.
Remove the last item in the array that is equal to this input value.
true
if a matching element was found and removed,
or false
if no matching element was found.
Forcibly re-sort the array using its previously assigned comparator function. This might be used to repair the array, if its items are no longer guaranteed to be in correct sorted order.
The array items will be sorted using the Array sort
function.
This is not guaranteed to be stable in all cases. See:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#sort_stability
this SortedArray.
Reverse the items in the array, and update the array's comparator function to account for this new reversed sort order. Later insertions into this SortedArray will respect the reversed sort order.
this SortedArray.
Get the items in the array from a start to an end index as a new SortedArray.
Optional
start: numberGet items starting at this index, inclusive.
Defaults to 0
, i.e. the beginning of the array.
Optional
end: numberGet items ending at this index, exclusive. Defaults to the length of the array.
a new SortedArray containing the given array slice.
Determines whether the specified callback function returns true for any element of an array.
A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.
Optional
thisArg: anyAn object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Re-sort the array and assign a new comparator function.
The array items will be sorted using the Array sort
function.
This is not guaranteed to be stable in all cases. See:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#sort_stability
Optional
compareFunc: SortedArrayComparatorFunction<T>The new comparator function to use for this SortedArray. Uses SortedArray.DefaultComparatorFunction by default, if no comparator function is specified.
this SortedArray.
Remove items from the array, starting at a given index.
Start removing items from the array at this index.
Optional
deleteCount: numberThe number of items that should be removed.
A new SortedArray containing the removed items.
Remove items from the array, starting at a given index, and insert new items at that index.
Warning: If inserting the provided items
would invalidate
the implementation's assumptions about array items being in sorted
order, then the implementation will behave in unexpected ways.
Use this method with caution.
Start removing items from the array at this index.
The number of items that should be removed.
Rest
...items: T[]A list of items which should be newly inserted in place of the removed items. The implementation assumes that these items can be inserted without violating the sort order of the SortedArray.
A new SortedArray containing the removed items.
Static
fromConstruct a new SortedArray and insert the values in an iterable or array-like object.
The values that should be inserted and sorted in the newly constructed SortedArray.
Optional
compareFunc: SortedArrayComparatorFunction<T>A custom comparator function, to use instead of SortedArray.DefaultComparatorFunction.
Optional
equalityFunc: SortedArrayEqualityFunction<T>A custom equality function, to use instead of SortedArray.DefaultEqualityFunction.
the newly constructed SortedArray, containing the given values in sorted order.
Static
fromConstruct a new SortedArray, initializing it with some values in an iterable or array-like object that are already provided in sorted order.
The values that should be inserted in the newly constructed SortedArray. They must be sorted according to the used comparator function, otherwise the returned SortedArray may behave unexpectedly.
Optional
compareFunc: SortedArrayComparatorFunction<T>A custom comparator function, to use instead of SortedArray.DefaultComparatorFunction.
Optional
equalityFunc: SortedArrayEqualityFunction<T>A custom equality function, to use instead of SortedArray.DefaultEqualityFunction.
the newly constructed SortedArray, containing the given assumed-sorted values.
Static
isStatic
ofConstruct a new SortedArray and insert the given values.
Rest
...values: T[]The values that should be inserted and sorted in the newly constructed SortedArray.
the newly constructed SortedArray, containing the given values in sorted order.
Static
ofConstruct a new SortedArray, initializing it with some values that are already provided in sorted order.
Rest
...values: T[]The values that should be inserted in the newly constructed SortedArray. They must be sorted according to SortedArray.DefaultComparatorFunction, otherwise the returned SortedArray may behave unexpectedly.
the newly constructed SortedArray, containing the given assumed-sorted values.
Generated using TypeDoc
The SortedArray type is a subclass of the base JavaScript Array type whose elements are kept in a sorted order.
Methods like SortedArray.insert are provided as an alternative to the typical array
push
method for inserting new elements in sorted order.Some methods, such as SortedArray.indexOf provide optimized implementations of Array methods, which may operate more efficiently upon sorted lists.
Warning: The SortedArray type does not stop you from still calling methods like
push
,shift
, orsplice
, which may invalidate the assumptions that SortedArray methods make about array contents being correctly sorted. These methods should be used with care, if they are used at all. Invalidating the sort order of a SortedArray will cause many operations to behave in unexpected ways.