2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,11 +1,11 @@
defmodule Average do
def median([]), do: nil
def median(list) do
len = Enum.count(list)
len = length(list)
sorted = Enum.sort(list)
mid = div(len, 2)
rem = rem(len, 2)
(Enum.at(sorted, mid) + Enum.at(sorted, mid + rem - 1)) / 2
if rem(len,2) == 0, do: (Enum.at(sorted, mid-1) + Enum.at(sorted, mid)) / 2,
else: Enum.at(sorted, mid)
end
end