Sorting algorithm in Javascript

后端 未结 5 561
情深已故
情深已故 2021-01-29 09:23

Write a JavaScript callback for the jQuery function $(\"#sort\").click. Allow the user to enter three numbers in any order. Output the numbers in ord

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-29 10:18

    Here's another (short) solution:

    $(document).ready(function () {
        $("#sort").click(function () {
            var msg = [$("#a").val(), $("#b").val(), $("#c").val()].sort(
            function (a, b) {
                return a - b;
            });
            alert(msg);
        });
    });
    

提交回复
热议问题