March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
|
|
@ -0,0 +1,29 @@
|
|||
function modes(values)
|
||||
dict = Dict() # Values => Number of repetitions
|
||||
modesArray = typeof(values[1])[] # Array of the modes so far
|
||||
max = 0 # Max of repetitions so far
|
||||
|
||||
for v in values
|
||||
# Add one to the dict[v] entry (create one if none)
|
||||
if v in keys(dict)
|
||||
dict[v] += 1
|
||||
else
|
||||
dict[v] = 1
|
||||
end
|
||||
|
||||
# Update modesArray if the number of repetitions
|
||||
# of v reaches or surpasses the max value
|
||||
if dict[v] >= max
|
||||
if dict[v] > max
|
||||
empty!(modesArray)
|
||||
max += 1
|
||||
end
|
||||
append!(modesArray, [v])
|
||||
end
|
||||
end
|
||||
|
||||
return modesArray
|
||||
end
|
||||
|
||||
println(modes([1,3,6,6,6,6,7,7,12,12,17]))
|
||||
println(modes((1,1,2,4,4)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue