ID:158286
 
Ok lets say I have this list:

list(1,2,3,4,5,5,5,5,5,5,5,5,5,5,5,6,7,8,9)

5 obviously appears more than any other number.

But how can I tell, using code, which number appears most in a list?
proc/mode(var/list/L)
if(!L || !L.len) return
var/list/found = list()
var/mostfound = 1
var/foundmost = L[1]
for(var/v in L)
found[v]++
if(found[v] > mostfound)
mostfound = found[v]
foundmost = v
return foundmost


<edit>fixed an error that was brought up in another thread. Had the inner-most two assignment statements switched around.
In response to Garthor
Its a lot more complex to do this than I thought in terms of code required, but thanks very much