<sort>
<sort>
is an General Operator component that reorders a list of components based on given criteria.
Attributes and Properties
Attribute | Type | Values |
---|---|---|
asList = "…" | "true" "false" | |
assignNames = "…" | ||
assignNamesSkip = "…" | ||
sortByComponent = "…" | integer | |
sortByProp = "…" | ||
sortVectorsBy = "…" | text | "displacement" "tail" |
type = "…" |
Property | Type |
---|---|
$s.sortByComponent | integer |
$s.sortVectorsBy | text |
Example: <sort>
a list of numbers
In this example, <number>
component are sorted in increasing order using the <sort>
component.
Example: <sort>
numbers from a random selection
In this example, randomly selected numbers generated with a <selectRandomNumbers>
component are sorted in increasing order using the <sort>
component.
Example: <sort>
numbers from user-input
In this example, numbers entered by the user with a <mathInput>
component are referenced by name and are sorted in increasing order using the <sort>
component.
Example: alphabetical sorting
In this example, names entered by the user with a <textInput>
component are referenced by name and are sorted in alphabetical order using the <sort>
component.
Example: assignNames
Sorted values can be assigned names directly using the assignNames
attribute.
Example: sortByComponent
For multi-dimensional object like points, sorting by sortByComponent="1"
sorts by their first component, i.e., their -component, while using sortByComponent="2"
results in sorting based on the -component.
Values entered outside the dimensions of the object, such as entering a or a in for a two-dimensional object, will result in no sorting.
Example: sortByProp
Components with numerical properties can be sorted based on an individual property. In this example, the points are sorted in ascending order based on their -coordinates, and then by their -coordinates.
Example: sortVectorsBy
Vectors can be sorted based on the location of their tail
or by their displacement
.
When sorted based on tail
, Doenet defaults to sorting based on the -coordinate unless specified otherwise using sortByProp="y"
.
When sorted based on displacement
, Doenet defaults to sorting based on the displacement in the -direction unless specified otherwise using sortByProp="x2"
, as in this example. This is because vector displacements are individually accessed using the convention: x1
for the horizontal displacement, and x2
for the vertical displacement.