Greatest element of a list: Difference between revisions

Content deleted Content added
→‎{{header|Euphoria}}: example edited to be compatible with the earlier versions of Euphoria
→‎{{header|Euphoria}}: added more trivial example
Line 354: Line 354:


=={{header|Euphoria}}==
=={{header|Euphoria}}==
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
for i = 1 to length( sArr ) do
Line 376: Line 376:


sequence s
sequence s
s = { "antelope", "dog", "cat", "cow", "wolf", "wolverine", "aardvark"}
s = {"ant", "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:
<pre>
1234
wolverine
</pre>

===More trivial example===
<lang euphoria>function get_biggest(sequence s)
object biggun
biggun = s[1]
for i = 2 to length(s) do
if compare(s[i], biggun) > 0 then
biggun = s[i]
end if
end for
return biggun
end function

constant numbers = {1,1234,62,234,12,34,6}
printf(1,"%d\n",get_biggest(numbers))

constant animals = { "antelope", "dog", "cat", "cow", "wolf", "wolverine", "aardvark"}
printf(1,"%s\n",{get_biggest(animals)})</lang>

Output:
Output:
<pre>
<pre>