Skip to content

Commit

Permalink
Use with to make it more simple
Browse files Browse the repository at this point in the history
  • Loading branch information
terenceponce committed Nov 29, 2023
1 parent c1fed6c commit c509804
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions lib/solutions/00013_roman_to_integer/roman_to_integer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,12 @@ defmodule LeetCodePractice.Solutions.RomanToInteger do
|> Enum.with_index()

Enum.reduce(values, 0, fn {x, i}, acc ->
if i < length(values) - 1 do
next = Enum.at(values, i + 1) |> elem(0)

if x < next do
acc - x
else
acc + x
end
with true <- i < length(values) - 1,
next <- values |> Enum.at(i + 1) |> elem(0),
true <- x < next do
acc - x
else
acc + x
_ -> acc + x
end
end)
end
Expand Down

0 comments on commit c509804

Please sign in to comment.