sorting 1.0.0

Array sorting

Linux macOS Windows



Description

Array sorting module. This module uses Quicksort algorithm as its backend.

Installation
Use Dima to install or update this module:
$ dima install sorting


Usage 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
 


Module Info
Author: @faruq (Muhammad Faruq Nuruddinsyah)
URL: https://dinfio.org/
Documentation: Module Reference
Published on: 23 April 2021