我正在为体育赛事做一个 php 应用程序,在某些情况下,得分的最小值是赢家。就像如果有 100 米赛跑比赛,那么获胜者就是跑得最快的。获胜者有最短的时间完成比赛。
但是我面临的是,当有人缺席或在完成之前退出时,我们提供的分数为零。在这种情况下,当我们要排序时,第一个位置将是零。但这应该是最后。
下面是我在 javascript 中的代码
var sorted = $(".result").sort(function (ib1, ib2) {
return parseFloat($(ib2).val()) - parseFloat($(ib1).val());
});
// Result Names
$('#result_first').val($("#participant"+$(sorted.get(9)).data("section")).val());
$('#result_second').val($("#participant"+$(sorted.get(8)).data("section")).val());
$('#result_third').val($("#participant"+$(sorted.get(7)).data("section")).val());
$('#result_fourth').val($("#participant"+$(sorted.get(6)).data("section")).val());
$('#result_fifth').val($("#participant"+$(sorted.get(5)).data("section")).val());
$('#result_sixth').val($("#participant"+$(sorted.get(4)).data("section")).val());
$('#result_seventh').val($("#participant"+$(sorted.get(3)).data("section")).val());
$('#result_eighth').val($("#participant"+$(sorted.get(2)).data("section")).val());
$('#result_ninth').val($("#participant"+$(sorted.get(1)).data("section")).val());
$('#result_tenth').val($("#participant"+$(sorted.get(0)).data("section")).val());
// Result Numbers
$('#result_first_no').val($(sorted.get(9)).val());
$('#result_second_no').val($(sorted.get(8)).val());
$('#result_third_no').val($(sorted.get(7)).val());
$('#result_fourth_no').val($(sorted.get(6)).val());
$('#result_fifth_no').val($(sorted.get(5)).val());
$('#result_sixth_no').val($(sorted.get(4)).val());
$('#result_seventh_no').val($(sorted.get(3)).val());
$('#result_eighth_no').val($(sorted.get(2)).val());
$('#result_ninth_no').val($(sorted.get(1)).val());
$('#result_tenth_no').val($(sorted.get(0)).val());
Run Code Online (Sandbox Code Playgroud)
请帮我对这些值进行排序,零值应该放在最后。
javascript ×1