Last active
May 16, 2016 20:53
-
-
Save wende/b2d8dc898b5d0e7d22f9063e8f06b6c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment