Created
February 6, 2016 05:04
-
-
Save jmsevold/fb49165d743b15793e80 to your computer and use it in GitHub Desktop.
reverse a list in elixir
This file contains 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
defmodule ListReverse do | |
def reverse(list) do | |
reverse(list,[]) | |
end | |
defp reverse([h|t],result) do | |
reversed = [h] ++ result | |
reverse(t,reversed) | |
end | |
defp reverse([],result) do | |
result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
more compact version ;)