code: function det(a) {
      var alen = a.length,
      alend = alen * 2,
      vals = new Array(alend),
      rowshift = alen - 1,
      colshift = alend - 1,
      mrow = rowshift - alen + 1,
      mcol = colshift,
      i = 0,
      result = 0,
      j;
      // check for special 2x2 case
      if (alen === 2) {
        return a[0][0] * a[1][1] - a[0][1] * a[1][0];
      }
      for (; i < alend; i++) {
        vals[i] = 1;
      }
      for (i = 0; i < alen; i++) {
        for (j = 0; j < alen; j++) {
          vals[(mrow < 0) ? mrow + alen : mrow ] *= a[i][j];
          vals[(mcol < alen) ? mcol + alen : mcol ] *= a[i][j];
          mrow++;
          mcol--;
        }
        mrow = --rowshift - alen + 1;
        mcol = --colshift;
      }
      for (i = 0; i < alen; i++) {
        result += vals[i];
      }
      for (; i < alend; i++) {
        result -= vals[i];
      }
      return result;
    }
docs: calculate the determinant of a matrix