Permalink
Browse files

refactor: pattern match only

  • Loading branch information...
antonydenyer committed Nov 16, 2017
1 parent 4a463fe commit e75fd6c4f82bf9e7e9e094cbf350d57330fbec00
Showing with 14 additions and 2 deletions.
  1. +14 −2 lib/roman.ex
View
@@ -83,8 +83,20 @@ defmodule Roman do
to_roman(number - 4, roman_accumulator <> "IV")
end
def to_roman(number, roman_accumulator) when number <= 3 do
roman_accumulator <> String.duplicate("I", number)
def to_roman(number, roman_accumulator) when number >= 3 do
to_roman(number - 3, roman_accumulator <> "III")
end
def to_roman(number, roman_accumulator) when number >= 2 do
to_roman(number - 2, roman_accumulator <> "II")
end
def to_roman(number, roman_accumulator) when number >= 1 do
roman_accumulator <> "I"
end
def to_roman(number, roman_accumulator) when number >= 0 do
roman_accumulator
end
def to_roman(number) do

0 comments on commit e75fd6c

Please sign in to comment.