Osama Usmani
Osama Usmani

Reputation: 13

How to Sort the Array in Min to Max in NetLogo

I want to sort the array in NetLogo. Like this {{array: 22 16 10 7}}

how can I achieve it?

Thanks

Upvotes: 0

Views: 115

Answers (2)

Seth Tisue
Seth Tisue

Reputation: 30453

The array extension doesn't provide for sorting.

Consider using a list instead. Normally in NetLogo we use lists and agentsets for everything; using arrays at all is rare.

But, assuming you really need a sorted array, you could copy the array to a list, sort the list, then make a new array from the result. (Or store the sorted items back into the original array, one at a time.)

Upvotes: 1

HappyR
HappyR

Reputation: 43

Did you try using sort-by? I guess that will do the magic.

Upvotes: 0

Related Questions