Module sorting

← Back to All Modules





Description

Array sorting module. This module uses Quicksort and Counting Sort algorithms as its backend.


Constants

There are no constants.


Functions


Classes

There are no classes.


Example

import sorting
 
start
    data = [
        {age: 20, name: "clara"},
        {age: 22, name: "vania"},
        {age: 18, name: "sarah"},
        {age: 17, name: "aisha"},
        {age: 18, name: "nifa"},
        {age: 19, name: "lisa"},
    ]
 
    usort(data, comparison())
    writer(data)
stop
 
function comparison(a, b)
    ' Compare a.age & b.age first, and then compare a.name & b.name
    ' if both ages are equal
 
    c = compare(a.age, b.age)
 
    if c == 0
        return compare(a.name, b.name)
    else
        return c
    endif
stop