Constructor
new SortedArray(comparatoropt, itemsopt)
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
comparator |
function |
<optional> |
ORDER.ASCENDING | Comparator function |
items |
Array.<*> |
<optional> |
[] | Optional array of items (will be sorted) |
- Source:
Classes
Members
comparator
- Source:
items
- Source:
Methods
add(item) → {boolean}
Adds the item in sorted position if no equivalent exists.
Parameters:
| Name | Type | Description |
|---|---|---|
item |
* |
- Source:
Returns:
True if added
- Type
- boolean
has(item) → {boolean}
Tests if an equivalent item exists (based on comparator).
Parameters:
| Name | Type | Description |
|---|---|---|
item |
* |
- Source:
Returns:
- Type
- boolean
remove(item) → {boolean}
Removes an equivalent item (if present).
Parameters:
| Name | Type | Description |
|---|---|---|
item |
* |
- Source:
Returns:
True if removed
- Type
- boolean
(static) logSearch(item, array, comparator, startopt, endopt) → {Array.<number, (*|undefined)>}
Performs binary search over a sorted array.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
item |
* | The item to search |
||
array |
Array.<*> | A sorted array |
||
comparator |
function | Comparison function |
||
start |
number |
<optional> |
0 | Inclusive start index |
end |
number |
<optional> |
array.length | Exclusive end index |
- Source:
Returns:
A pair [index, result]
- Type
- Array.<number, (*|undefined)>