title: Compute the distance between elements in a bi-dimensional array in Javascript
body: <p>Having the following input string: <code>923857614</code></p>
  <p>This is represented into a matrix like this:</p>
  <pre><code>9 2 3
  8 5 7
  6 1 4 
  </code></pre>
  <p>Having a moving sequence like this: 423692, this means that we start in point 4, we move to 2, then to 3, then to 6, then to 9 and finally to 2.</p>
  <p>It must be computed the length of the road. At beginning it starts from 0, if the next step is adjacent to the current one, add 1, if it isn't adjacent, add 2.</p>
  <p>How I tried to do it:</p>
  <pre><code>function computeRoadLength(keypad, movingSequence) {
    // build the matrix
   const arr = [[keypad[0], keypad[1], keypad[2]],
                [keypad[3], keypad[4], keypad[5]], 
                [keypad[6], keypad[7], keypad[8]]];
    let roadLength = 0;
    for (i = 0; i &lt; movingSequence.length; i++) {
      // some way to compute the distance here
      if (arr[i] &gt; arr[i+1]) roadLength = roadLength + 1;
      if (arr[i] &lt; arr[i+1]) roadLength = roadLength + 2;
    }
  
    return roadLength;
  }
  
  computeRoadLength(923857614, 423692); // 2 + 1 + 2  + 2  + 1 = 8, should return 8
  </code></pre>