Ar Sort

From GECK
Jump to: navigation, search


A function added by the New Vegas Script Extender.

Description

Attempts to sort the elements of an array in ascending or descending order and returns a new regular array (list) containing the elements in sorted order (keys associated with the elements are lost, if source is a map type).

In order to be sorted all elements of an array must be of the same type (strings, numbers, or objects). If this condition is not met an empty array is returned.

Strings are sorted alphabetically and case-insensitively, numbers are sorted numerically, and objects are sorted by formID. By default the elements are sorted in ascending order, the optional flag sorts descending.

Syntax

[help]
(array) Ar_Sort Source:anyarray SortDescending:bool 

Example

array_var aOriginal
array_var aSorted

let aOriginal := Ar_List 1, 5, 2

let aSorted := Ar_Sort aOriginal ; * 1, 2, 5

let aSorted := Ar_Sort aOriginal, 1 ; * 5, 2, 1

Notes

  • If the order of values is not important, Ar_Sort can function as a quick way to pass all values in a map or stringmap to a regular array, comparable to Ar_Keys for keys.

See Also