ARS. - Array Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Arrays and Data-Structures > ARS. - Array's > !ARS. - Array Sorting >

ARS. - Array Operations

ARS.DualSort

Previous Top Next


MiniRobotLanguage (MRL)

 

ARS.DualSort

Sorts the first array and mirrors the sorting in the second tag array.

 

Intention

 

The ARS.DualSort command sorts the first array ($$ARR) in ascending order and applies the same permutation to a second tag array ($$ARB),

ensuring both arrays remain synchronized.

Each array can independently be of type Integer, FP (Floating Point), or String, allowing flexible pairings like sorting names (String) with scores (Integer).

 

Illustration:

📦 Before Sort:
$$ARR: [3, 1, 4]
$$ARB: [A, B, C]
🔄 After Sort:
$$ARR: [1, 3, 4]
$$ARB: [B, A, C]

 

Syntax

 

ARS.DualSort|P1|P2

 

Parameter Explanation

 

P1 - $$ARR - (Variable)

The handle of the first array to be sorted (Integer, FP, or String).

P2 - $$ARB - (Variable)

The handle of the second tag array to be permuted (Integer, FP, or String).

 

Example

 

'***********************************

' ARS.DualSort - Sample 1

'***********************************

ARS.New|$$ARR|i

ARS.New|$$ARB|s

ARS.Add|$$ARR|3

ARS.Add|$$ARR|1

ARS.Add|$$ARR|4

ARS.Add|$$ARB|A

ARS.Add|$$ARB|B

ARS.Add|$$ARB|C

ARS.DualSort|$$ARR|$$ARB

DBP.Sorted $$ARR: [1, 3, 4], $$ARB: [B, A, C]

ARS.End|$$ARR

ARS.End|$$ARB

'

 

Remarks

- Sorting is ascending (numerical for Integer/FP, alphabetical for String).

- Use ARS.Reverse on both arrays post-sort for descending order.

 

Limitations:

- Both arrays must be initialized and typically should have the same size for meaningful results.

 

See also:

ARS.New

ARS.Add

ARS.Reverse