JSFiddle - React, Tailwind, and code Playground
by Arvind Pal
JavaScript
const str = "()(".split("");
let isBalance = str.reduce((p, el) =>{
if(p <0){
return p
}
if(el === "("){
return ++p
}
if(el === ")") {
return --p
}
return p ;
},0);
console.log("isbalance ===>", isBalance);