Stack Exchange Vote Simulator Write a program or function that takes in a string only containing the characters ^ and v (you can assume there will be no other characters). Read from left to right this string represents the sequence of mouse clicks a single user made while viewing a Stack Exchange question or answer for the first time.

Every ^ represents a click of the upvote button and every v represents a click of the downvote button. (For working examples look slightly left.)

Assume that no voting limitations are in effect so all the clicks are registered correctly.
Print or return:


1 or +1 if the post ends up being upvoted.
0 if the post ends up not being voted on. (-0 and +0 are not valid)
-1 if the post ends up being downvoted.


Posts start with zero net votes from the user and the buttons change the net votes as follows:

Net Votes Before    Button Pressed    Net Votes After
1                   ^                 0
1                   v                 -1
0                   ^                 1
0                   v                 -1
-1                  ^                 1
-1                  v                 0


The shortest code in bytes wins.

Test cases:

[empty string] -&gt; 0
^^ -&gt; 0
^v -&gt; -1
^ -&gt; 1
v -&gt; -1
v^ -&gt; 1
vv -&gt; 0
^^^ -&gt; 1
vvv -&gt; -1
^^^^ -&gt; 0
vvvv -&gt; 0
^^^^^ -&gt; 1
vvvvv -&gt; -1
^^^^^^ -&gt; 0
vvvvvv -&gt; 0
^^v -&gt; -1
^v^ -&gt; 1
^vv -&gt; 0
vv^ -&gt; 1
v^v -&gt; -1
v^^ -&gt; 0
^vvv^^vv^vv^v^ -&gt; 1
^vvv^^vv^vv^v^^ -&gt; 0
^vvv^^vv^vv^v^^^ -&gt; 1
^vvv^^vv^vv^v^^v -&gt; -1
^vvv^^vv^vv^v^^vv -&gt; 0
^vvv^^vv^vv^v^^vvv -&gt; -1
^vvvvvvvvvvvv -&gt; 0
^^vvvvvvvvvvvv -&gt; 0
^^^vvvvvvvvvvvv -&gt; 0
vvv^^^^^^^^^^^^ -&gt; 0
vv^^^^^^^^^^^^ -&gt; 0
v^^^^^^^^^^^^ -&gt; 0
Gol>&lt;> 0.3.11, 13 12 11 bytes

iEh`^=:@)+M


Try it online. Even though this will work fine in the next update, I've listed it as 0.3.11 just in case.

Explanation

i               Read char
 Eh             If EOF, halt and output top of stack as num
   `^=          Push 1 if char is ^, else 0
      :@        Dup and rotate, giving [is^ is^ votecount]
        )       Compare greater than, pushing 1 or 0 as appropriate
         +M     Add and subtract 1


Note that the first use of @ pulls a 0 from the bottom of the stack to initialise the vote count for the first iteration

To illustrate with a full table:

Votes before    Button    Is ^?    Compare &lt;    Add     Subtract 1
     1            ^         1         0          1          0
     1            v         0         0          0         -1
     0            ^         1         1          2          1
     0            v         0         0          0         -1
    -1            ^         1         1          2          1
    -1            v         0         1          1          0