Jump to content

Greatest element of a list: Difference between revisions

→‎{{header|ooRexx}}: add variant working for any comparable objects
(→‎list of any strings: corrected mal-formed HTML tag "/PRE". -- ~~~~)
(→‎{{header|ooRexx}}: add variant working for any comparable objects)
Line 1,259:
 
=={{header|ooRexx}}==
===version===
<lang ooRexx>
-- routine that will work with any ordered collection or sets and bags containing numbers.
Line 1,276 ⟶ 1,277:
return largest
</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}}==
2,300

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.