code: private static double crank(double[] w) {
          int n = w.length;
          double s = 0.0;
          int j = 1;
          while (j < n) {
              if (w[j] != w[j - 1]) {
                  w[j - 1] = j;
                  ++j;
              } else {
                  int jt = j + 1;
                  while (jt <= n && w[jt - 1] == w[j - 1]) {
                      jt++;
                  }
  
                  double rank = 0.5 * (j + jt - 1);
                  for (int ji = j; ji <= (jt - 1); ji++) {
                      w[ji - 1] = rank;
                  }
  
                  double t = jt - j;
                  s += (t * t * t - t);
                  j = jt;
              }
          }
  
          if (j == n) {
              w[n - 1] = n;
          }
  
          return s;
      }
docs: Given a sorted array, replaces the elements by their rank, including
  midranking of ties, and returns as s the sum of f<sup>3</sup> - f, where
  f is the number of elements in each tie.