I like parentheticals (a lot).
by mschock
HTML
<pre></pre>
JavaScript
var sentence = "Sometimes (when I nest them (my parentheticals) too much (like this (and this))) they get confusing."
function findMatch(sentence, startPosition) {
var openParens = 0;
for (var i = startPosition; i < sentence.length; i++) {
if (sentence[i] === '(') {
openParens += 1;
} else if (sentence[i] === ')') {
openParens -= 1;
if (openParens === 0) {
return i;
}
}
}
return -1;
}
document.getElementsByTagName('pre')[0].innerHTML =
'End Position: ' + findMatch(sentence, 10);