Balanced brackets: Difference between revisions

m
→‎Functional JS: Tested and refreshed output.
(→‎Functional JS: Generalised the code a little. (Other bracket types, mixed strings))
m (→‎Functional JS: Tested and refreshed output.)
Line 3,373:
iNext = iDepth + (
strBrackets.includes(h) ? (
openBracket === xs[0]h ? (
1
) : -1
Line 3,403:
const
stringLength = 2 * pairCount,
sstrSample = randomBrackets(stringLength);
return "'" + sstrSample + "'" +
strPad.slice(2 + stringLength) + maybe('OK')(
iUnMatched => 'problem\n' +
' '.repeat(1 + iUnMatched) + '^'
)(
findUnbalancedBracket('[]')(sstrSample)
);
}).join('\n')
Line 3,452:
})();</lang>
{{Out}}
<pre>'' OK
'[]' OK
'[]]][[' problem
^
^
'[]]][[' problem
^
'[][[]]]]][[[' problem
^
'[][[][]][]]' OK
']]][[][][[[]][]' problem
^</pre>
 
9,655

edits