<sort>
<sort> is a General Operator component that reorders a list of components based on given criteria.
Attributes and Properties
Attributes for <sort>
Other (5)
asListboolean. Default value: true. Whether to render the items separated by commas (true) or with no separator (false).
integer. Default value: 1. Index of the component to sort by (when sorting vectors).
text. Name of a property to sort by (e.g. "x" for sorting points by x-coordinate).
keyword. Whether to sort vectors by component or by magnitude.
| Value | Description |
|---|---|
displacement (default) | Sort vectors by their displacement components. |
tail | Sort vectors by the position of their tail point. |
typetext. Component type to sort children as.
Common to all components (9)
copyreference. Create an independent copy of another component by reference. Enter a references a $name.
disabledboolean. Default value: false. Whether this component is disabled and cannot be interacted with.
extendreference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.
fixedboolean. Default value: false. Whether this component's value is fixed and cannot be modified.
fixLocationboolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
hideboolean. Default value: false. Whether to hide this component from the rendered output.
isResponseboolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.
nametext. The name used to reference this component from elsewhere in the document.
styleNumberinteger. Default value: 1. The style number used to select this component's visual styling from the available style definitions.
Properties for <sort name="s">
Other (2)
$s.sortByComponentinteger. Index of the component to sort by (when sorting vectors).
$s.sortVectorsBytext. Whether to sort vectors by component or by magnitude.
Common to all components (4)
$s.doenetMLtext. The DoenetML source code that produced this component.
$s.hideboolean. Whether to hide this component from the rendered output.
$s.isResponseboolean. Whether this component is treated as a response for the purposes of assessment.
$s.styleNumberinteger. The style number used to select this component's visual styling from the available style definitions.
Examples
Example: <sort> a list of numbers
In this example, <number> components 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.
Attribute Examples
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.
Attribute 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.
Attribute 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.