ReferencesortIndices

<sortIndices>

The indices that put a list in sorted order, rather than the sorted values

<sortIndices> is a General Operator component that renders the positions that put its arguments in sorted order, rather than the sorted values themselves. The first entry of the result is the index of the smallest value, the second is the index of the next smallest, and so on.

It accepts everything <sort> accepts and orders values identically — including sortByProp for sorting components by one of their properties. The difference is only in what it reports.

Its value comes from being combined with indexing: $other[$perm[1]] reads one list in the order determined by another.

Attributes and Properties

Attributes for <sortIndices>

Highlighted (3)
asList

boolean. Default value: true. Whether to render the items separated by commas (true) or with no separator (false).

sortByProp

text. Name of a property to sort by (e.g. "x" for sorting points by x-coordinate).

type

keyword. Component type to sort bare string children as. Omit it and they are read as what they look like: every piece naming a number sorts by value, anything else sorts alphabetically.

ValueDescription
numberRead bare strings as numbers, ordered by value.
mathRead bare strings as math expressions, ordered by value.
textRead bare strings as text, ordered alphabetically.
booleanRead bare strings as booleans, ordered with false before true.
Sort order (3)
sortByComponent

integer. Default value: 1. Index of the component to sort by (when sorting vectors).

sortByProp

text. Name of a property to sort by (e.g. "x" for sorting points by x-coordinate).

sortVectorsBy

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.
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 <sortIndices name="s">

Sort order (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: the sorting permutation

The smallest value, 10, is in position 2 of the original list, so the result starts with 2.


Example: sorting one list by another

Sorting one list by the values of another is not expressible with <sort> alone, because <sort> returns the values it sorted and discards where they came from.


Example: sorting points by a coordinate

sortByProp works exactly as it does on <sort>: point BB has the smallest xx-coordinate, so it comes first.