Skip to content

Commit c509804

Browse files
committed
Use with to make it more simple
1 parent c1fed6c commit c509804

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

lib/solutions/00013_roman_to_integer/roman_to_integer.ex

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,12 @@ defmodule LeetCodePractice.Solutions.RomanToInteger do
3333
|> Enum.with_index()
3434

3535
Enum.reduce(values, 0, fn {x, i}, acc ->
36-
if i < length(values) - 1 do
37-
next = Enum.at(values, i + 1) |> elem(0)
38-
39-
if x < next do
40-
acc - x
41-
else
42-
acc + x
43-
end
36+
with true <- i < length(values) - 1,
37+
next <- values |> Enum.at(i + 1) |> elem(0),
38+
true <- x < next do
39+
acc - x
4440
else
45-
acc + x
41+
_ -> acc + x
4642
end
4743
end)
4844
end

0 commit comments

Comments
 (0)