Skip to content

Instantly share code, notes, and snippets.

@doomspork
Created April 7, 2018 15:28
Show Gist options
  • Save doomspork/99f516cf415b99ada51441896f190d26 to your computer and use it in GitHub Desktop.
Save doomspork/99f516cf415b99ada51441896f190d26 to your computer and use it in GitHub Desktop.
defmodule Example do
def reverse(list, acc \\ [])
def reverse([], acc) do
acc
end
def reverse([head|tail], acc) do
reverse(tail, [head | acc])
end
end
@doomspork
Copy link
Author

defmodule Example do
  def reverse([head]) do
    [head]
  end

  def reverse([head|tail]) do
    reverse(tail) ++ [head]
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment