grade

From The K Language Wiki
Revision as of 06:41, 9 July 2022 by Promovicz (talk | contribs) ("Better category ordering, add redirects to categories, fix pseudo-adverb categories")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Grade
<x
>x

grade returns the domain of a collection (list, table, or dictionary) sorted by its range. It has two versions: up (<x) and down (>x), a.k.a. asc and desc by analogy with SQL.

Grade uses a stable sorting algorithm - equivalent items are sorted in their original order.

Sorting (as in sorting the range by itself) can be implemented through the idiom x@<x or x@>x. K7 and k9 support an additional dedicated sort-ascending primitive: ^x.

 >34 -1 0 67 32767
4 3 0 2 1

 {x(<x)}("xyz";"a";"k";"j";"apl";"bqn")
("apl"
 "bqn"
 "xyz"
 "a"
 "j"
 "k")