# [JavaScript (Node.js)], <s>&nbsp;80&nbsp;</s> 66 bytes

Returns `[towards, away]`.

<!-- language-all: lang-javascript -->

    s=>Buffer(s).map(c=>+s?s=0:c<96?p|=c<95:s=++a[p^c&1],a=[0,p=0])&&a

[Try it online!](https://tio.run/##ZYpBCsIwEADvPiRNSC3xoGBxW/AFvZcalthIpXZDVz1Jvh6DVw/DHGbu@EZ26xSe24WuY/KQGJrzy/txlayqBwbpoNHcMpjanY6HNnwge18zaI19uDixG0qE3pQBzKCEwORoYZrHaqab9LKwlmKXiVQotfmLXSSKFH@DtXlJXw "JavaScript (Node.js) – Try It Online")

###Commented

    s =>                      // s = input string
      Buffer(s)               // turn s into a buffer
      .map(c =>               // for each ASCII code c:
        +s ?                  //   if s is a positive numeric value:
          s = 0               //     ignore this character; set s to 0
        :                     //   else:
          c < 96 ?            //     if c is less than 96:
            p |= c < 95       //       set p to 1 if c < 95 (must be 80, for 'P')
          :                   //     else:
            s =               //       set s to a positive numeric value,
                              //       so that the next character is ignored
              ++a[p ^ c & 1], //         increment a[p] if c is even (126 for '~')
                              //         or p[p ^ 1] if c is odd (111 for 'o')
        a = [0, p = 0]        //    start with a = [0, 0] and p = 0
      ) && a                  // end of map(); return a[]


----------


# [JavaScript (Node.js)], <s>&nbsp;112&nbsp;</s> 102 bytes

[JavaScript (Node.js)]: https://nodejs.org

A version with error checking, as per the original rules of the challenge.

<!-- language-all: lang-javascript -->

    s=>Buffer(s).some(c=>n?n-=c:c-111&&c-126?c-95?c-80|p++:0:!++a[n=c^17,p^c&1],a=[n=0,p=0])|p-1?'error':a

[Try it online!](https://tio.run/##dczLCsIwEAXQvX/hpk1pUxrBVyAt@AXdSxtCTESpmZCoq5Jfr/GxUxczA3Mu9yzuwkt3slds4KAmzSbP6t1Na@WQz0oPF4Ukq01jMJNUYkJIksSzWDUSb5dxbarR5jmt6DzPxd4w2ZN1YXuZkK4QLD6qwrKqy0aLSZMq58ClVEwSjIdBlQMckUYp5xDaOAHSLJt9YRsAAoRXgPOfkY/@sXd3@1t5LH3S9AA "JavaScript (Node.js) – Try It Online")