Greatest element of a list: Difference between revisions
Content added Content deleted
(→list of any strings: corrected mal-formed HTML tag "/PRE". -- ~~~~) |
Walterpachl (talk | contribs) (→{{header|ooRexx}}: add variant working for any comparable objects) |
||
Line 1,259: | Line 1,259: | ||
=={{header|ooRexx}}== |
=={{header|ooRexx}}== |
||
===version=== |
|||
<lang ooRexx> |
<lang ooRexx> |
||
-- routine that will work with any ordered collection or sets and bags containing numbers. |
-- routine that will work with any ordered collection or sets and bags containing numbers. |
||
Line 1,276: | Line 1,277: | ||
return largest |
return largest |
||
</lang> |
</lang> |
||
===version 2 works with any strings=== |
|||
<lang>/* REXX *************************************************************** |
|||
* 30.07.2013 Walter Pachl as for REXX |
|||
**********************************************************************/ |
|||
s=.list~of('Walter','lives','in','Vienna') |
|||
say listMax(s) |
|||
-- routine that will work with any ordered collection or sets and bags. |
|||
::routine listMax |
|||
use arg list |
|||
items=list~makearray -- since we're dealing with different collection types, reduce to an array |
|||
if items~isEmpty then return .nil -- return a failure indicator. could also raise an error, if desired |
|||
largest = items[1] |
|||
-- note, this method uses one extra comparison. It could use |
|||
-- do i = 2 to items~size to avoid this |
|||
do item over items |
|||
If item>>largest Then |
|||
largest = item |
|||
end |
|||
return largest</lang> |
|||
=={{header|Oz}}== |
=={{header|Oz}}== |