Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: How to find the N largest values in an array?

by japhy (Canon)
on Oct 03, 2001 at 23:04 UTC ( [id://116540]=note: print w/replies, xml ) Need Help??


in reply to How to find the N largest values in an array?

The simplest way is just to sort the values numerically and get the top values:
my $n = 3; # top three my @highest = (sort { $b <=> $a } @num)[0 .. $n-1];

Replies are listed 'Best First'.
Re: Answer: Find largest ordered sequence in an array
by Anonymous Monk on Oct 03, 2001 at 23:18 UTC
    The problem is that the values are ordered by time and i need the 3 values to be "in a row" not just the 3 highest. the purpose of this is to "read" a peak in traffic. if i just pull out 3 highest it doesnt represent an average. thanks though, im looking to see if i can somehow use this.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://116540]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-19 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found