Skip to content

Commit

Permalink
Replace when with if for nextChar
Browse files Browse the repository at this point in the history
  • Loading branch information
ageron committed Sep 17, 2024
1 parent bc34648 commit fe962b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
"uuid": "5c7dbb9d-8816-4bbb-ba33-057ecf4f6329",
"practices": [],
"prerequisites": [],
"difficulty": 1
"difficulty": 3
},
{
"slug": "pangram",
Expand Down
26 changes: 12 additions & 14 deletions exercises/practice/matching-brackets/.meta/Example.roc
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ isPaired = \string ->
when remainingChars is
[] -> List.isEmpty openBrackets # ok or missing closing bracket
[nextChar, .. as restChars] ->
when nextChar is
open if isOpen open ->
help (openBrackets |> List.append open) restChars

close if isClose close ->
when openBrackets is
[] -> Bool.false # missing opening bracket
[.. as restOpen, open] ->
if isMatch (open, close) then
help restOpen restChars
else
Bool.false # mismatching brackets

_otherChar -> help openBrackets restChars
if isOpen nextChar then
help (openBrackets |> List.append nextChar) restChars
else if isClose nextChar then
when openBrackets is
[] -> Bool.false # missing opening bracket
[.. as previousOpens, lastOpen] ->
if isMatch (lastOpen, nextChar) then
help previousOpens restChars
else
Bool.false # mismatching brackets
else
help openBrackets restChars

help [] (string |> Str.toUtf8)

0 comments on commit fe962b4

Please sign in to comment.