编写max(list) 返回列表最大元素

 1 defmodule MyList do
 2 
 3   def max(list), do: _max(list, 0)
 4 
 5   defp _max([], max), do: max
 6 
 7   defp _max([head | tail], max) do
 8     _max(tail, (head > max && head) || max)
 9   end
10 end
View Code

 

posted on 2019-05-27 14:41  c3tc3tc3t  阅读(279)  评论(0编辑  收藏  举报