sort. Sorting hash   [3.4.4]

^hash.sort[key;value]{function_sorting_by_string}
^hash.sort[key;value]{function_sorting_by_string}[sorting_direction]
^hash.sort[key;value](function_sorting_by_number)
^hash.sort[key;value](function_sorting_by_number)[sorting_direction]

The given method sorts the hash fields according to the specified function.

Sorting_function is the function, whose current value determines the position of the field in the final (sorted) variant of the hash. This value may be a string (values are compared in alphabetical order) or a number (values are compared as float numbers).

Sorting_direction determines sorting direction. The parameter may have two values:
desc-descending
asc-ascending
Ascending value is used by default.

Example
$men[^hash::create[
   $.
Sergey(26)
   $.Alex(20)
   $.Mishka(29)
]]
^men.sort[name;]{$name}
^men.
foreach[name;age]{
    $
name$age
}[
<br />]

As the result of this code, the
$men hash will be sorted according to the name values:
Alex: 20
Mishka: 29 
Serge
y: 26 

You may sort the hash by age values in descending order (
desc) if you substitute the line of the code which is calling method sort for this one:
^men.sort[;age]($age)[desc]

The code will result in:
Mishka: 29
Sergey: 26
Alex: 20




Copyright © 1997–2021 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 30.03.2016