Balanced brackets: Difference between revisions
m
→{{header|Ecstasy}}
Line 2,389:
=={{header|Ecstasy}}==
<syntaxhighlight lang="java">
module BalancedBrackets {
Boolean balanced(String text) {▼
{▼
▲ Boolean balanced(String text)
Int depth = 0;
for (Char ch : text) {
switch (ch, depth) {
case (']',
return
--depth;▼
}
}
@Inject Console console;
void run() {
String[] tests =
[
Line 2,426 ⟶ 2,421:
];
Int longest = tests.map(s -> s.size).reduce(0, (max, len) -> max.maxOf(len));
for (String test : tests) {
console.print($"{test}{' ' * (longest-test.size)} {balanced(test) ? "OK" : "NOT OK"}");
}
}
}
</syntaxhighlight>
|