<sort>

Sorts a list according to a comparison function

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

Attributes and Properties

Attributes for <sort>

Other (5)
asList

boolean. 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.

ValueDescription
displacement (default)Sort vectors by their displacement components.
tailSort vectors by the position of their tail point.
type

text. Component type to sort children as.

Common to all components (9)
copy

reference. Create an independent copy of another component by reference. Enter a references a $name.

disabled

boolean. Default value: false. Whether this component is disabled and cannot be interacted with.

extend

reference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.

fixed

boolean. Default value: false. Whether this component's value is fixed and cannot be modified.

fixLocation

boolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

hide

boolean. Default value: false. Whether to hide this component from the rendered output.

isResponse

boolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.

name

text. The name used to reference this component from elsewhere in the document.

styleNumber

integer. 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.sortByComponent

integer. Index of the component to sort by (when sorting vectors).

$s.sortVectorsBy

text. Whether to sort vectors by component or by magnitude.

Common to all components (4)
$s.doenetML

text. The DoenetML source code that produced this component.

$s.hide

boolean. Whether to hide this component from the rendered output.

$s.isResponse

boolean. Whether this component is treated as a response for the purposes of assessment.

$s.styleNumber

integer. 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 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.


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 xx-coordinates, and then by their yy-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 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.