Operator Type:
Operator Scope of Action:
Operator Purpose:
Data Type Returned:
Operator First Added:
Operator in Current Baseline:
Operator Last Altered:
Operator Has Optional Arguments:
Function [other Function type actions]
Item [operators of similar scope]
Data manipulation [other Data manipulation operators]
List [about List data type]
v5.8.0
Baseline
As at baseline
Syntax note: Operators without any defined mandatory arguments may omit their empty closing parentheses
List.nsort([attributeRefStr])
List.nsort()
For List-type list data, the basic form
$MyList = $MyList.nsort();
$MyList = $MyList.nsort().reverse();
re-sorts the referenced list's values in ascending numerical sort order. This means sorting '1,2,11' not 1,11,2' such as occurs with sort() and a lexical sort. A numerical sort is really only useful for numerical data. This implies:
- Numbers or Interval-type (but not Date-type data)
- Strings that begin with numbers
For most string (text) values and Date-type date, consider List.sort() or List.isort(), both of which give lexical sorts of differing case sensitivity. The resulting sort order can be reversed overall by chaining the List.nsort() and List.reverse() functions:
$MyList = $MyList.nsort().reverse();
Use of sorting with Set-type data
This operator does not usually apply to Set-type lists because, as from v9.0.0, Sets now auto-sort A–Z and cannot be (reliably) user-sorted to a different order. However, is passing the result to a List-type or to some other process—i.e. passing the sorted result, not the source Set—then sorted content is possible
List.nsort(attributeRefStr)
Here the referenced list must be a list of note names or paths, i.e. list $Name data or $Path data (but not a mix of the two). If note names are not unique within the document, path values must be used to achieve correct sort. This form of sort cannot be used with any other sort of value list. This operator cannot be applied to any list of values, unlike the short form above.
In this form, the sort order can be based on the value of the stipulated attributeRefStr (a $-prefixed attribute name). The attribute's value is derived from the item identified by the $Name or $Path of the list item being evaluated:
$MyList = $collect(children, $Name).nsort($PageNumber);
$MyList = $collect_if(find($Prototype=="pProduct"), $Price>0,$Path).nsort($Price);
In this long form usage, the sort ordering is based on the data type of attributeRefStr:
- Number-type: and Interval-type: numerical sort
- Date-type: sort on date (implied numerical)
- All other types lexical
See also—notes linking to here: