JSFiddle - React, Tailwind, and code Playground
by Prathameshsb
JavaScript
function test(s){
let arr = s.split('');
let st = [];
for(let i = 0; i < arr.length; i++) {
if(arr[i] === '(') {
st.push(arr[i]);
}else if(arr[i] == ')' && st.length) {
st.pop();
}else if(arr[i] === ')') {
arr[i] = '';
}
}
while(st.length) {
let curr = st.pop();
arr[curr] = '';
}
return arr.join('')
}
console.log(test('lee(t(c)o)d(((e)'))