Advertisement
doanhtu

Elixir max function

Mar 18th, 2018
988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.18 KB | None | 0 0
  1. defmodule Max do
  2.   def max([]), do: nil
  3.   def max([x]), do: x
  4.   def max([x, y]) when x > y, do: x
  5.   def max([x, y]), do: y
  6.   def max([head | tail]), do: max([head, max(tail)])
  7. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement