Elixir 自作のListのMax関数

[ruby]
defmodule ListMax do
def max(list), do: _max(list, 0)
defp _max([], max), do: max
defp _max([head | tail], max) do
if head > max do
result = head
else
result = max
end
_max(tail, result)
end
end
[/ruby]

[bash]
iex(82)> IO.puts ListMax.max([471,193,433,263,102])
471
[/bash]

This entry was posted in Elixir, 技術情報. Bookmark the permalink.

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です