Welcome, Guest. Please login or register.
Did you miss your activation email?
05/22/12, 18:28
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  General
| |-+  Flash and AS 3 (Moderators: papachan, kofi addaquay)
| | |-+  Finding the mode amongst a list of numbers?
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: Finding the mode amongst a list of numbers?  (Read 1001 times)
worked
Seasoned Programmer
***
Posts: 129


View Profile Email
« on: 03/20/11, 22:05 »

Hey there-  I need to find the mode from an array of numbers.  How might I do that?  For instance, if I have, "12, 13, 13, 13, 14, 15, 15".  13 would be the mode as it's found more often than any other number.  Any code snipets are appreciated!  Thanks!
Logged
kofi addaquay
Global Moderator
Senior Programmer
*****
Posts: 450



View Profile WWW Email
« Reply #1 on: 03/21/11, 09:22 »

what i would do is write a loop to go through an array [12, 13, 13, 13, 14, 15, 15] and find all the unique numbers. they will be

12, 13, 14, and 15

i would put those in another array. then run each of the unique number against the first array but only counting if the number already exist.
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #2 on: 03/21/11, 10:00 »

you could do it with a single loop.

first element - just copy to another two dimensional array({value:value,count:1})

with the next elements you search, if found, add 1 to count, if not, create a new element.

At the end, you have an array, having the unique values, and the number of theire occurance.

Now you only need to sort the two dimensional array by count, and read the highest value.
Logged

happy flashing
Cool
Ronald
worked
Seasoned Programmer
***
Posts: 129


View Profile Email
« Reply #3 on: 04/07/11, 17:09 »

Thanks!  This project has been put on hold, but will be returning to it shortly...  I'll def refer back to your suggests when I do.
Logged
stevenfrank38
Server what's that
*
Posts: 3


View Profile Email
« Reply #4 on: 04/15/11, 20:33 »

It's ok. But agree with the system shown by Ronald. I think this is the perfect one..
Logged

Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
anything