Forum Discussion
SmartBear_Suppo
Alumni
15 years agoHi Armen,
The expression list[2] means "the element with index 2 in the array list", which is the date column in your first question (indexing of arrays start with 0 in most programming languages -- e.g. the third element has index 2). So
Changing the number two to something else would be a good start. You might even want to make it an argument to the function, something like this:
The expression list[2] means "the element with index 2 in the array list", which is the date column in your first question (indexing of arrays start with 0 in most programming languages -- e.g. the third element has index 2). So
if (list[2] < firstOrdered[2])means "if the date in list is smaller/earlier than the date in firstOrdered".
Changing the number two to something else would be a good start. You might even want to make it an argument to the function, something like this:
/*
* Sorts the sub arrays in myArray based on comparison of the n:th element in the sub arrays.
*
* @param myArray The array which contains the sub arrays.
* @param n The index of the element to sort the sub arrays by.
*/
def extractFirstOrdered( myArray, n )
{
firstOrdered = null
for( list in myArray )
{
if( firstOrdered == null || list[n] < firstOrdered[n] )
firstOrdered = list
}
myArray.remove( firstOrdered )
return firstOrdered
}