diff --git a/lib/list_ops.ex b/lib/list_ops.ex index 3010084..eaa75a5 100644 --- a/lib/list_ops.ex +++ b/lib/list_ops.ex @@ -1,2 +1,21 @@ defmodule ListOps do + def count([]) do + 0 + end + + def count([_head | tail]) do + 1 + count(tail) + end + + def reverse(list) do + reverse(list, []) + end + + defp reverse([], acumulator) do + acumulator + end + + defp reverse([head | tail], acumulator) do + reverse(tail, [head | acumulator]) + end end diff --git a/test/list_ops_test.exs b/test/list_ops_test.exs index c16ecd3..617e680 100644 --- a/test/list_ops_test.exs +++ b/test/list_ops_test.exs @@ -39,15 +39,15 @@ defmodule ListOpsTest do # end # # test "filter of empty list" do - # assert ListOps.filter([], &odd?/1) == [] + # assert ListOps.filter([], &Integer.is_odd/1) == [] # end # # test "filter of normal list" do - # assert ListOps.filter([1,2,3,4], &odd?/1) == [1,3] + # assert ListOps.filter([1,2,3,4], &Integer.is_odd/1) == [1,3] # end # # test "filter of huge list" do - # assert ListOps.filter(Enum.to_list(1..1_000_000), &odd?/1) == + # assert ListOps.filter(Enum.to_list(1..1_000_000), &Integer.is_odd/1) == # Enum.map(1..500_000, &(&1*2-1)) # end #