Operator Scope of Action:
Operator First Added:
The basic form
$MyList = $MyList.nsort()
$MyList = $MyList.nsort().reverse()
This function 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. For text, consider List.sort() or List.isort(), both of which give lexical sorts of differing case sensitivity. Or, if using $Name or $Path data, use the optional long from (below) and let the nominated attribute's data type set the form of sort, e.g for date sorting, sort on a Date-type attribute.
The resulting sort order can be reversed overall by chaining the List.nsort() and List.reverse() functions.
Here the referenced list must be a list of note names or paths, i.e. a 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 $Attribute, being derived from the item identified by the $Name or $Path that is the lis 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 $Attribute:
- Number type:- numerical sort
- Date type: sort on date (implied numerical)
- All other types lexical