Balanced brackets: Difference between revisions
→{{header|J}}: Generate & test pairs
(→{{header|J}}: genBracketPairs handles array argument) |
(→{{header|J}}: Generate & test pairs) |
||
Line 41:
bracketDepth =: '[]' -&(+/\)/@:(=/) ]
checkBalanced =: _1 -.@e. bracketDepth</lang>
'''Examples''':<lang j> (,&'
][
][[]
[
[][[]][] OK
[][[[][
[]][]][]][[[
[[]][[][][]][] OK
]]]][[][][[[[]][
[]]][][][[[[]][[]]
'''Comments''': This task highlights the versatility and usefulness of J's scanning modifiers, <code>/</code> and <code>\</code>.
|