数组推送调用后方括号中的语句的目的是什么?

What is the purpose of a statement in square brackets after an array push call?

我一直在 FreeCodeCamp 上解决一个名为 "9 billion names of God the integer". (The specifics of the problem itself aren't germane to my question, but have a look at the link if you're interested.) Admittedly I wrestled with this problem for several days before giving up and googling the answer. The problem originally comes from Rosetta Code, and I set about reading the answer provided for JavaScript 的问题,以确保我了解如何解决这个问题。

据我所知,它是通过很好的老式 for 循环进行计算的,尽管它是用简短的、非描述性的变量名发布的,但我想我可以通过自己的方式完成它。然而,这是让我感到困惑的部分(请注意,下面的代码是 Rosetta Code 解决方案的清理复制品,其中有很多不必要的注释和一些拼写错误):

(function() {
  var cache = [
    [1]
  ];

  function cumu(n) {
    var r, l, x, Aa, Mi;
    for (l = cache.length; l < n + 1; l++) {
      r = [0];
      for (x = 1; x < l + 1; x++) {
        r.push(r[r.length - 1] + (Aa = cache[l - x < 0 ? cache.length - (l - x) : l - x])[(Mi = Math.min(x, l - x)) < 0 ? Aa.length - Mi : Mi]);
      }
      cache.push(r);
    }
    return cache[n];
  }

  function row(n) {
    var r = cumu(n),
      leArray = [],
      i;
    for (i = 0; i < n; i++) {
      leArray.push(r[i + 1] - r[i]);
    }
    return leArray;
  }

  console.log("Rows:");
  for (iterator = 1; iterator < 12; iterator++) {
    console.log(row(iterator));
  }

  console.log("Sums");
  [23, 123, 1234].forEach(function(a) {
    var s = cumu(a);
    console.log(a, s[s.length - 1]);
  });
})()

特别是 cumu(n) 中的这一行:

r.push(r[r.length - 1] + (Aa = cache[l - x < 0 ? cache.length - (l - x) : l - x])[(Mi = Math.min(x, l - x)) < 0 ? Aa.length - Mi : Mi]);

push 方法后面有 [square brackets]。那有什么作用?我知道括号的用途,因为它们与数组和对象有关,但我找不到有关此用法的任何文档。请注意,脚本似乎无论如何都按预期工作,结果按预期打印到控制台,没有出现错误。

(Aa = cache[l - x < 0 ? cache.length - (l - x) : l - x]) 

returns 一个数组,因为 cache 是一个多维数组。它在括号之间,因为 Aa 也需要设置。

这段代码的最大问题是难以阅读。打开您的 IDE 并逐段重组代码可能是明智的。这样你就能更好地理解它了。