JSFiddle - React, Tailwind, and code Playground

by Aaron Zhang

JavaScript

function findParentheses(str,start,arr){
    var i = 0;
    while(i < str.length){
        if(str[i] == '('){
            i = findParentheses(str.substring(i+1),i,arr);
        }
        else if(str[i] == ')'){
            arr.push([start,i]);
            return i;
        }
        ++i;
    }
}

var str = '((abc),(def))';
var result = {};
findParentheses(str,0,result);
console.log(result);