Skip to content

Commit

Permalink
refactor(phone-number): prefer cond to case for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine-duchenet committed Sep 15, 2023
1 parent a488fea commit e1f0b67
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions exercises/practice/phone-number/.meta/example.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ defmodule PhoneNumber do
end

defp validate_length(number) do
case String.length(number) do
invalid when invalid < 10 -> {:error, "must not be fewer than 10 digits"}
invalid when invalid > 11 -> {:error, "must not be greater than 11 digits"}
_valid -> {:ok, number}
length = String.length(number)

cond do
length < 10 -> {:error, "must not be fewer than 10 digits"}
length > 11 -> {:error, "must not be greater than 11 digits"}
true -> {:ok, number}
end
end

Expand Down

0 comments on commit e1f0b67

Please sign in to comment.