sort given block in ascending order
Parameters
sort collection :literal :pathliteral :dictionary :block
Attributes
as |
:literal |
localized by ISO 639-1 language code |
sensitive |
|
case-sensitive sorting |
descending |
|
sort in descending order |
values |
|
sort dictionary by values |
by |
:string, :literal |
sort array of dictionaries by given key |
Returns
Examples
copy
a: [3 1 6]
print sort a ; 1 3 6
copy
print sort.descending a ; 6 3 1
copy
b: ["one" "two" "three"]
sort 'b
print b ; one three two
copy
; Creating a Priority Queue
tasks: []
; add tasks with priorities
'tasks ++ #[priority: 3 task: "Low priority"]
'tasks ++ #[priority: 1 task: "Urgent!"]
'tasks ++ #[priority: 2 task: "Important"]
; sort by priority
sorted: sort.by: 'priority tasks
loop sorted 'item ->
print [item\priority ":" item\task]
; 1 : Urgent!
; 2 : Important
; 3 : Low priority
copy
spanishWords: ["uno","dos","tres","Uno","perversión","ábaco","abismo", "aberración"]
sort.as: 'es spanishWords
; => ["ábaco" "aberración" "abismo" "dos" "perversión" "tres" "uno" "Uno"]
copy
sort.sensitive ["c" "C" "CoffeeScript" "nim" "Arturo" "coffeescript" "arturo" "Nim"]
; => ["Arturo" "C" "CoffeeScript" "Nim" "arturo" "c" "coffeescript" "nim"]
copy
sort.values #[ name: "John" surname: "Doe" age: 35 income: 5000]
; => #[age: 35 income: 5000 surname: "Doe" name: "John" ]
Related