<sort>

<sort> is an General Operator component that reorders a list of components based on given criteria.

Attributes and Properties

Attributes for <sort>
AttributeTypeValues
asList = "…""true" "false"
assignNames = "…"
assignNamesSkip = "…"
sortByComponent = "…"integer
sortByProp = "…"
sortVectorsBy = "…"text"displacement" "tail"
type = "…"
Props for <sort name="s">
PropertyType
$s.sortByComponentinteger
$s.sortVectorsBytext

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 xx-component, while using sortByComponent="2" results in sorting based on the yy-component.

Values entered outside the dimensions of the object, such as entering a 33 or a 00 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 xx-coordinates, and then by their yy-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 xx-coordinate unless specified otherwise using sortByProp="y".

When sorted based on displacement, Doenet defaults to sorting based on the displacement in the xx-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.