MaximumItem (Arraylist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
Line 26: Line 26:


==Examples==
==Examples==
For the <var>ArrayList</var> <code>%al</code> whose items are the odd integers between 0 and 10, <code>%al:maxItem</code> returns <code>9</code>.
For the <var>ArrayList</var> <code>%al</code> whose items are the odd integers between 0 and 10, <var>MaximumItem</var> returns the value of the item that has the maximum value, while <var>Maximum</var> returns the index (item number) of that item:
<p class="code">b                                 
                                   
%al  is arraylist of float         
%al = list(1,3,5,7,9)
 
printText {~=%al:maximumItem}
printText {~=%al:maximum}
end </p>
 
The result is:
<p class="output">%al:maximumItem=9  
%al:maximum=5 </p>


==See also==
==See also==
{{Template:Arraylist:MaximumItem footer}}
{{Template:Arraylist:MaximumItem footer}}

Revision as of 22:16, 18 July 2012

Get item that has maximum value (Arraylist class)

[Introduced in Sirius Mods 7.8]


MaximumItem is related to the Maximum Arraylist method, which returns the number or name of the item that has the maximum value in an Arraylist.

Syntax

%item = al:MaximumItem[( [itemFunction])]

Syntax terms

%item An Arraylist item of the same type as the al object.
al An Arraylist object.
method A function that operates on the type of the items in the Arraylist. It may be a local method or method variable or a class member (Variable, Property), and it must return an intrinsic value. The default method value is the special identity function, This, which simply returns the item value.

Usage notes

  • The optional method parameter lets you further manipulate the Arraylist item values before performing the MaximumItem method's item evaluation. If your Arraylist items are not intrinsic values, you must specify a method function that can map the item values to intrinsic values or the method will fail.

Examples

For the ArrayList %al whose items are the odd integers between 0 and 10, MaximumItem returns the value of the item that has the maximum value, while Maximum returns the index (item number) of that item:

b %al is arraylist of float %al = list(1,3,5,7,9) printText {~=%al:maximumItem} printText {~=%al:maximum} end

The result is:

%al:maximumItem=9 %al:maximum=5

See also