Greatest element of a list: Difference between revisions
Content deleted Content added
m →{{header|PostScript}}: added works with |
→{{header|Euphoria}}: example edited to be compatible with the earlier versions of Euphoria |
||
Line 354: | Line 354: | ||
=={{header|Euphoria}}== |
=={{header|Euphoria}}== |
||
{{works with|Euphoria 4.0.0}} |
|||
Applying a function to each element of an array |
Applying a function to each element of an array |
||
<lang Euphoria>function aeval( sequence sArr, integer id ) |
<lang Euphoria>function aeval( sequence sArr, integer id ) |
||
for i = 1 to length( sArr ) do |
|||
sArr[ i ] = call_func( id, { sArr[ i ] } ) |
|||
end for |
|||
return sArr |
|||
end function |
end function |
||
object biggun |
object biggun |
||
function biggest( object elem ) |
function biggest( object elem ) |
||
if compare(elem, biggun) > 0 then |
|||
biggun = elem |
|||
end if |
|||
return elem |
|||
end function |
end function |
||
</lang> |
|||
biggun = 0 |
|||
Example runs |
|||
object a |
|||
<lang Euphoria>biggun = 0 |
|||
a = aeval( {1,1234,62,234,12,34,6}, routine_id("biggest") ) |
|||
printf( 1, "%d\n", biggun ) |
printf( 1, "%d\n", biggun ) |
||
sequence s |
|||
s = { "antelope", "dog", "cat", "cow", "wolf", "wolverine", "aardvark"} |
|||
biggun = "ant" |
biggun = "ant" |
||
a = aeval( s, routine_id("biggest") ) |
a = aeval( s, routine_id("biggest") ) |
||
printf( 1, "%s\n", {biggun} )</lang> |
printf( 1, "%s\n", {biggun} )</lang> |
||
Output |
Output: |
||
<pre> |
<pre> |
||
1234 |
1234 |