修复这个三重嵌套三元运算符的最佳方法是什么?

What is the best way to fix this triple-nested ternary operator?

我有一个对对象数组进行排序的代码片段。每个对象看起来像:

{
      "id": "60ff9eb7c793c6197dae5d42",
      "matches": 1,
      "timestamp": "2021-07-27T05:46:52.469Z",
      "likes": 23
}

我有一个三重嵌套的三元表达式,首先按匹配对它们进行排序,然后按喜欢,然后按时间戳。代码如下。

        bestMatches.sort((a, b) =>
          a.matches < b.matches
            ? 1
            : a.matches === b.matches
            ? a.likes < b.likes
              ? 1
              : a.likes === b.likes
              ? a.timestamp.getTime() < b.timestamp.getTime()
                ? 1
                : -1
              : -1
            : -1
        );

将其转换为“好”代码的最佳方法是什么?在这种情况下,我在使用 if/elses 时遇到了很多困难,而且我知道嵌套三元表达式是不好的做法。一如既往,如果您花时间回答或试图回答这个问题,感谢您的宝贵时间。

先减去 matches,再减去 likes,再减去次数。

bestMatches.sort((a, b) => (
  (b.matches - a.matches) ||
  (b.likes - a.likes) ||
  (b.timestamp.getTime() - a.timestamp.getTime())
));