Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: Finding the max()/min()

by sleepingsquirrel (Hermit)
on Dec 19, 2004 at 01:40 UTC ( #415925=note: print w/replies, xml ) Need Help??


in reply to Re^3: Finding the max()/min()
in thread Finding the max()/min()

There's a bug in that code, try finding the max of this list...
@a = (1,0,3,2);


-- All code is 100% tested and functional unless otherwise noted.

Replies are listed 'Best First'.
Re^5: Finding the max()/min()
by elusion (Curate) on Dec 19, 2004 at 02:21 UTC
    Good catch; I forgot the edge case. Here's the fix:
    sub max { my $max = shift; return $max if not @_; my $next = shift; unshift @_, $max > $next ? $max : $next; goto &max; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://415925]
help
Chatterbox?
[LanX]: values %{ $DBI->fetchrow_has href('column_name' }
[LanX]: ehm ... fetchall_hashref
[Jenda]: my int @a = ^5_000_000 Coerces the argument to Numeric, and generates a range from 0 up to (but excluding) the argument.
[Jenda]: The apparent design principle of Perl6 operators was "Let's confuse 'em dudes." Whose braindead idea was this particular operator and the three hundred around it?

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2018-07-16 16:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (344 votes). Check out past polls.

    Notices?