### sort-by

#### sort-by reporter-task list
sort-by reporter-task 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 task.

The two inputs to the reporter task are the values being compared. The task should report true if `?1` comes strictly before `?2` 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 [length ?1 < length ?2] ["Grumpy" "Doc" "Happy"]
    => ["Doc" "Happy" "Grumpy"]

See also sort, sort-on.

Take me to the full NetLogo Dictionary