Skip to main content
3 of 3
deleted 4 characters in body
Julian
  • 3.2k
  • 7
  • 17

PowerShell Core, 102 bytes

$s=-1
switch -r($args[$args.Count..0]){.{$a=-$a;$s=-$s}~{$a--}}"$s`x+$a"|% *ce '+-','-'|% *ce '1x','x'

Try it online!

Passes an expression as a string using splatting
Then processes it from right to left
For each char, negate $s and $a, and if the char is ~ , decrement $a
Then concatenate them all: $s + "x+" + $a
Replace +- with -
Remove the useless 1 before x

Julian
  • 3.2k
  • 7
  • 17