krzysztof-w
5/16/2016 - 8:47 PM

curl_2_poison.ex

def common_root(xs, root), do: common_root(xs, root, String.length(root))
def common_root([h | _] = xs, root \\ "", length \\ 0) do
  newroot = elem(String.split_at(h, length + 1), 0)
  if Enum.all?(xs, &String.starts_with?(&1, newroot)) do
    common_root(xs, newroot, length + 1)
  else
    root
  end
end