如何根据多个条件对不同输出的列表进行排序。反应
我试图根据他们的分数对参赛者进行排序。如果分数相同,我想对它们进行对另一个值进行排序。
到目前为止 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 havesetSortedEntrants(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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
条件应如下。您放置了正确的代码缩进,然后可以找出三元运营商的匹配条款。
the condition should be as follows. You put the right code indentation, then you can figure out the matching clauses of ternary operator.