Algosim documentation: sort

sort

Sorts a container using a standard comparer.

Syntax

Description

If X is any container, then sort(X) returns X sorted using the default comparer. sort(X, cpr) uses the standard comparer named cpr:

To use a custom comparer, use the CustomSort or the SortBy function instead.

Examples

Alice ≔ ExampleData("Alice in Wonderland");

WordWrap(
  join(
    first(
      RemoveAdjacentDuplicates(
        sort(
          filter(
            words(Alice),
            s ↦ ∀(s, (c ↦ ChrIsLetter(c) ∧ ChrIsLowerCase(c)))
          )
        )
      ),
      100
    )
  )
)
a, abide, able, about, above, absence, absurd, acceptance, accident,
accidentally, account, accounting, accounts, accusation, accustomed, ache,
across, act, actually, added, adding, addressed, addressing, adjourn, adoption,
advance, advantage, adventures, advice, advisable, advise, affair,
affectionately, afford, afore, afraid, after, afterwards, again, against, age,
ago, agony, agree, air, airs, alarm, alarmed, alas, alive, all, allow, almost,
alone, along, aloud, already, also, altered, alternately, altogether, always,
am, among, an, ancient, and, anger, angrily, angry, animal, animals, annoy,
annoyed, another, answer, answered, answers, anxious, anxiously, any, anything,
anywhere, appealed, appear, appearance, appeared, appearing, applause, apples,
arch, archbishop, arches, are, argue, argued, argument, arguments, arm, arms
A ≔ RandomIntMatrix(10, 0, 10)
⎛0  8  5  8  4  0  4  3  7  2⎞
⎜2  4  9  6  2  8  4  0  7  4⎟
⎜7  2  5  6  4  8  0  6  7  6⎟
⎜4  1  4  6  5  7  5  2  1  2⎟
⎜5  0  0  4  8  6  6  7  4  9⎟
⎜9  8  2  3  9  6  6  1  7  6⎟
⎜8  3  1  7  7  4  7  2  4  8⎟
⎜2  3  0  7  2  5  6  5  2  0⎟
⎜3  1  3  1  7  1  9  2  3  5⎟
⎝8  9  7  4  7  8  3  6  3  7⎠
sort(A)
⎛0  0  0  0  0  0  0  0  1  1⎞
⎜1  1  1  1  1  2  2  2  2  2⎟
⎜2  2  2  2  2  2  2  3  3  3⎟
⎜3  3  3  3  3  3  4  4  4  4⎟
⎜4  4  4  4  4  4  4  4  4  5⎟
⎜5  5  5  5  5  5  5  6  6  6⎟
⎜6  6  6  6  6  6  6  6  6  7⎟
⎜7  7  7  7  7  7  7  7  7  7⎟
⎜7  7  7  7  8  8  8  8  8  8⎟
⎝8  8  8  8  9  9  9  9  9  9⎠

See also