isParenthesisBalanced
JavaScript
by infous
JavaScript
function isParenthesisBalanced(str) {
const arr = str.split('');
return arr.reduce((function (prev, item) {
if (prev < 0) {
return prev;
}
return item === '('
? prev + 1
: prev - 1;
}), 0) === 0;
}
alert(isParenthesisBalanced('((()()))'));