如何根据多个条件对不同输出的列表进行排序。反应

发布于 2025-02-13 07:23:33 字数 770 浏览 1 评论 0原文

我试图根据他们的分数对参赛者进行排序。如果分数相同,我想对它们进行对另一个值进行排序。

到目前为止 setSortedEntrants(props.event.entrants.sort(((a,b)=>(A.Score< B.Score)?-1:1));>

>>在当前的参赛者中分类分数。我想补充一点,以便如果分数匹配,我想在另一个值上对a.scorecard.back9score vs b.scorecard.back9score进行对那些进行

排序非常正确的

setSortedEntrant(props.event.entrants.sort(((a,b)=>(a.score< b.score)?-1:A.Score ?scorecard.back9score<

b.score

1- if a.score is less than b.score, move up one
2 - if a.score equals b.score then if a.scoreCard.back9Score  is less than b.scoreCard.back9Score then move up one.
3 - otherwise if a.score > b.score move down one.

== 和scorecardback9score,数字

很明显,我出了错。

I am trying to sort a list of entrants depending on their scores. If the score are the same, I then want to sort them on another value.

So far I have
setSortedEntrants(props.event.entrants.sort((a, b) => (a.score < b.score) ? -1 : 1));

which sorts the entrants on their current score. I want to add to this, so that if the scores match, I then want to sort those on another value a.scoreCard.back9Score vs b.scoreCard.back9Score

I have tried this but doest seem to be quite right

setSortedEntrants(props.event.entrants.sort((a, b) => (a.score < b.score) ? -1 : a.score === b.score ? a.scoreCard.back9Score < b.scoreCard.back9Score: -1 ? a.score > b.score : 1));

logic being,

1- if a.score is less than b.score, move up one
2 - if a.score equals b.score then if a.scoreCard.back9Score  is less than b.scoreCard.back9Score then move up one.
3 - otherwise if a.score > b.score move down one.

all values for score and scoreCardback9Score and numbers

Is there somewhere obvious I am going wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怀念你的温柔 2025-02-20 07:23:33

条件应如下。您放置了正确的代码缩进,然后可以找出三元运营商的匹配条款。

        setSortedEntrants(props.event.entrants.sort((a, b) => 
            (a.score < b.score) ? 
              -1 
               : (a.score === b.score ? 
                     (a.scoreCard.back9Score < b.scoreCard.back9Score ? 
                     -1 
                     : 1)
                 : 1)
            );
        

the condition should be as follows. You put the right code indentation, then you can figure out the matching clauses of ternary operator.

        setSortedEntrants(props.event.entrants.sort((a, b) => 
            (a.score < b.score) ? 
              -1 
               : (a.score === b.score ? 
                     (a.scoreCard.back9Score < b.scoreCard.back9Score ? 
                     -1 
                     : 1)
                 : 1)
            );
        
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文