new module:ct-core /Ordered Set(elementsopt, field ToCompareopt)
A set that is ordered based on time of insertion. This set may contain only Strings or Numbers unless a field name is provided which can be used to retrieve a value from an object to make a comparison.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
elements |
Array |
<optional> |
an array whose elements are to be placed into this set. |
fieldToCompare |
String |
<optional> |
the field name to use when comparing objects. |
Methods
add(element, indexopt) → {boolean}
Adds an item into this set.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
element |
Object | the item to add. |
|
index |
Number |
<optional> |
the index at which the item will be added. If not included, element will be added to the end of the set. |
Returns:
true if the item was added, false if it was already present.
- Type
- boolean
add All(elements)
Adds all the items in the passed array to this set.
Parameters:
Name | Type | Description |
---|---|---|
elements |
Array | the items to add to this set. |
clear()
Clears all items from the set.
contains(element)
Tests to see if an item is in this set
Parameters:
Name | Type | Description |
---|---|---|
element |
Object | the item to test. |
Returns:
boolean, true if the item is in the set, false if it is not.
get(index)
Gets the element at a specified index.
Parameters:
Name | Type | Description |
---|---|---|
index |
Number | the index to get. |
Returns:
the object at the specified index.
get ByKey(key)
Gets the element by a defined key
Parameters:
Name | Type | Description |
---|---|---|
key |
key | the key used to retrieve item. |
Returns:
the object with the specified key, otherwise undefined.
get Contents()
Returns an Array with the same contents as the Set.
Returns:
An array representation of the Set.
get Field ToCompare()
Returns:
the field name used when comparing objects.
get Index Of(element)
Returns the index of the given element in the order.
Parameters:
Name | Type | Description |
---|---|---|
element |
Object |
remove(element) → {boolean}
Removes an item from this set.
Parameters:
Name | Type | Description |
---|---|---|
element |
Object | the item to remove. |
Returns:
true if the item had been in the set, false if it was not.
- Type
- boolean
remove All(elements)
Removes all the items in the passed array from this set.
Parameters:
Name | Type | Description |
---|---|---|
elements |
Array | the items to remove from this set. |
size()
Returns the number of elements contained in the set.
Returns:
the number of elements contained in the set.