function removeOuterParentheses(expression, outerLevel) {
    let cleanExpression = _.clone(expression);
    let newOuterLevel;
    if (outerLevel !== undefined) {
        newOuterLevel = outerLevel;
    }
    else {
        newOuterLevel = 0;
    }

    let hasOuter = cleanExpression[0] === '(';
    while (hasOuter) {
        let level = 1;
        for (let i = 1; i < cleanExpression.length - 1; ++i) {
            if (cleanExpression[i] === '(') {
                ++level;
            }
            else if (cleanExpression[i] === ')') {
                --level;
            }

            if (level === 0) {
                hasOuter = false;
            }
        }

        if (hasOuter) {
            cleanExpression = cleanExpression.substring(1, cleanExpression.length-1);
            hasOuter = cleanExpression[0] === '(';
            newOuterLevel++;
        }
    }

    if (outerLevel !== undefined) {
        return {
            expression: cleanExpression,
            level: newOuterLevel
        }
    }
    else {
        return cleanExpression;
    }
}
/*
    Removes the outermost parentheses from the expression
*/
Removes the outermost parentheses from the expression
Removes the outermost parentheses from the expression
function removeOuterParentheses(expression, outerLevel) {
    let cleanExpression = _.clone(expression);
    let newOuterLevel;
    if (outerLevel !== undefined) {
        newOuterLevel = outerLevel;
    }
    else {
        newOuterLevel = 0;
    }
    let hasOuter = cleanExpression[0] === '(';
    while (hasOuter) {
        let level = 1;
        for (let i = 1; i < cleanExpression.length - 1; ++i) {
            if (cleanExpression[i] === '(') {
                ++level;
            }
            else if (cleanExpression[i] === ')') {
                --level;
            }
            if (level === 0) {
                hasOuter = false;
            }
        }
        if (hasOuter) {
            cleanExpression = cleanExpression.substring(1, cleanExpression.length-1);
            hasOuter = cleanExpression[0] === '(';
            newOuterLevel++;
        }
    }
    if (outerLevel !== undefined) {
        return {
            expression: cleanExpression,
            level: newOuterLevel
        }
    }
    else {
        return cleanExpression;
    }
}
function removeOuterParentheses ( expression , outerLevel ) { let cleanExpression = _ . clone ( expression ) ; let newOuterLevel ; if ( outerLevel !== undefined ) { newOuterLevel = outerLevel ; } else { newOuterLevel = 0 ; } let hasOuter = cleanExpression [ 0 ] === '(' ; while ( hasOuter ) { let level = 1 ; for ( let i = 1 ; i < cleanExpression . length - 1 ; ++ i ) { if ( cleanExpression [ i ] === '(' ) { ++ level ; } else if ( cleanExpression [ i ] === ')' ) { -- level ; } if ( level === 0 ) { hasOuter = false ; } } if ( hasOuter ) { cleanExpression = cleanExpression . substring ( 1 , cleanExpression . length - 1 ) ; hasOuter = cleanExpression [ 0 ] === '(' ; newOuterLevel ++ ; } } if ( outerLevel !== undefined ) { return { expression : cleanExpression , level : newOuterLevel } } else { return cleanExpression ; } }
Removes the outermost parentheses from the expression
Removes the outermost parentheses from the expression