Skip to main content
saved 5 bytes
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

JavaScript (ES6), 268263 bytes

s=>s.replace(/\S+/g,v=>v>{}?s[0][1]=[[v,1]]:s=[[(u=[])|v||([[y,q],[x,u],...s]=s,S=v<"/"||-1,v+1|0?e|=u+''!=q:q.map(([U,e])=>(o=uu.find(o=>o[0]==U))?o[1]+=e*S:u||u.push([Uo=[U,e*S]0])&&o)[1]+=v<"/"?e:-e),eval(x+v+y)),u.filter(o=>o[1]).sort()],...s],e=s=[])|e?"*":s.reverse().join` `.split`,`.join``

Try it online!Try it online!

JavaScript (ES6), 268 bytes

s=>s.replace(/\S+/g,v=>v>{}?s[0][1]=[[v,1]]:s=[[(u=[])|v||([[y,q],[x,u],...s]=s,S=v<"/"||-1,v+1|0?e|=u+''!=q:q.map(([U,e])=>(o=u.find(o=>o[0]==U))?o[1]+=e*S:u.push([U,e*S])),eval(x+v+y)),u.filter(o=>o[1]).sort()],...s],e=s=[])|e?"*":s.reverse().join` `.split`,`.join``

Try it online!

JavaScript (ES6), 263 bytes

s=>s.replace(/\S+/g,v=>v>{}?s[0][1]=[[v,1]]:s=[[(u=[])|v||([[y,q],[x,u],...s]=s,v+1|0?e|=u+''!=q:q.map(([U,e])=>(u.find(o=>o[0]==U)||u.push(o=[U,0])&&o)[1]+=v<"/"?e:-e),eval(x+v+y)),u.filter(o=>o[1]).sort()],...s],e=s=[])|e?"*":s.reverse().join` `.split`,`.join``

Try it online!

saved 9 bytes
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

JavaScript (ES6), 277268 bytes

s=>s.replace(/\d+|(\w)|\S\S+/g,(v,u)=>uv=>v>{}?s[0][1]=[[v,1]]:s=[[(u=[])|v||([[y,q],[x,u],...s]=s,S=v<"/"||-1,v+1|0?e|=u+''!=q:q.map(([U,e])=>(o=u.find(o=>o[0]==U))?o[1]+=e*S:u.push([U,e*S])),eval(x+v+y)),u.filter(o=>o[1]).sort()],...s],e=s=[])|e?"*":s.reverse().join` `.split`,`.join``

Try it online!Try it online!

JavaScript (ES6), 277 bytes

s=>s.replace(/\d+|(\w)|\S/g,(v,u)=>u?s[0][1]=[[v,1]]:s=[[(u=[])|v||([[y,q],[x,u],...s]=s,S=v<"/"||-1,v+1|0?e|=u+''!=q:q.map(([U,e])=>(o=u.find(o=>o[0]==U))?o[1]+=e*S:u.push([U,e*S])),eval(x+v+y)),u.filter(o=>o[1]).sort()],...s],e=s=[])|e?"*":s.reverse().join` `.split`,`.join``

Try it online!

JavaScript (ES6), 268 bytes

s=>s.replace(/\S+/g,v=>v>{}?s[0][1]=[[v,1]]:s=[[(u=[])|v||([[y,q],[x,u],...s]=s,S=v<"/"||-1,v+1|0?e|=u+''!=q:q.map(([U,e])=>(o=u.find(o=>o[0]==U))?o[1]+=e*S:u.push([U,e*S])),eval(x+v+y)),u.filter(o=>o[1]).sort()],...s],e=s=[])|e?"*":s.reverse().join` `.split`,`.join``

Try it online!

saved 3 bytes
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

JavaScript (ES6), 280277 bytes

s=>s.replace(/\d+|(\w)|\S/g,(v,u)=>u?s[0][1]=[[v,1]]:s=[[1/v?s=[[(u=[],v):|v||([[y,q],[x,u],...s]=s,S=v<"/"||-1,v+1|0?e|=u+''!=q:q.map(([U,e])=>(o=u.find(o=>o[0]==U))?o[1]+=e*S:u.push([U,e*S])),eval(x+v+y)),u.filter(o=>o[1]).sort()],...s],e=s=[])|e?"*":s.reverse().join` `.split`,`.join``

Try it online!Try it online!

JavaScript (ES6), 280 bytes

s=>s.replace(/\d+|(\w)|\S/g,(v,u)=>u?s[0][1]=[[v,1]]:s=[[1/v?(u=[],v):([[y,q],[x,u],...s]=s,S=v<"/"||-1,v+1|0?e|=u+''!=q:q.map(([U,e])=>(o=u.find(o=>o[0]==U))?o[1]+=e*S:u.push([U,e*S])),eval(x+v+y)),u.filter(o=>o[1]).sort()],...s],e=s=[])|e?"*":s.reverse().join` `.split`,`.join``

Try it online!

JavaScript (ES6), 277 bytes

s=>s.replace(/\d+|(\w)|\S/g,(v,u)=>u?s[0][1]=[[v,1]]:s=[[(u=[])|v||([[y,q],[x,u],...s]=s,S=v<"/"||-1,v+1|0?e|=u+''!=q:q.map(([U,e])=>(o=u.find(o=>o[0]==U))?o[1]+=e*S:u.push([U,e*S])),eval(x+v+y)),u.filter(o=>o[1]).sort()],...s],e=s=[])|e?"*":s.reverse().join` `.split`,`.join``

Try it online!

saved 1 byte
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading
saved 3 bytes
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading