Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

program to parenthesize an expression

def p(e):
 for o in"+-*/":
    for i,c in enumerate(e):
        if(c==o)*(0==sum([(d=="(")-(d==")")for d in e[:i]])):return"("+p(e[:i])+o+p(e[i+1:])+")"
 return e
Source by codegolf.stackexchange.com #
 
PREVIOUS NEXT
Tagged: #program #parenthesize #expression
ADD COMMENT
Topic
Name
8+9 =