Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
13
Task/Averages-Mode/CoffeeScript/averages-mode.coffee
Normal file
13
Task/Averages-Mode/CoffeeScript/averages-mode.coffee
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
mode = (arr) ->
|
||||
# returns an array with the modes of arr, i.e. the
|
||||
# elements that appear most often in arr
|
||||
counts = {}
|
||||
for elem in arr
|
||||
counts[elem] ||= 0
|
||||
counts[elem] += 1
|
||||
max = 0
|
||||
for key, cnt of counts
|
||||
max = cnt if cnt > max
|
||||
(key for key, cnt of counts when cnt == max)
|
||||
|
||||
console.log mode [1, 2, 2, 2, 3, 3, 3, 4, 4]
|
||||
Loading…
Add table
Add a link
Reference in a new issue