NetLogo Help: sort-by

### sort-by1.3

#### sort-by reporter list sort-by reporter agentset

If the input is a list, reports a new list containing the same items as the input list, in a sorted order defined by the boolean reporter. reporter may be an anonymous reporter or the name of a reporter.

The two inputs to reporter are the values being compared. The reporter should report true if the first argument comes strictly before the second in the desired sort order, and false otherwise.

If the input is an agentset or a list of agents, reports a list (never an agentset) of agents.

If the input is a list, the sort is stable, that is, the order of items considered equal by the reporter is not disturbed. If the input is an agentset, ties are broken randomly.

    show sort-by < [3 1 4 2]
    => [1 2 3 4]
    show sort-by > [3 1 4 2]
    => [4 3 2 1]
    show sort-by [ [string1 string2] -> length string1 < length string2 ] ["Grumpy" "Doc" "Happy"]
    => ["Doc" "Happy" "Grumpy"]

See also sort, sort-on, -> (anonymous procedure).

Take me to the full NetLogo Dictionary