Sorting algorithm in Javascript

后端 未结 5 694
情深已故
情深已故 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:04

    This is also right, But Better you put all values into an array.

    Get All element value and push value into an array, Use array.sort();;

    to Sort numbers (numerically and ascending):

    arrayname.sort(function(a, b){return a-b});
    

    to Sort numbers (numerically and descending):

    arrayname.sort(function(a, b){return b-a});
    

提交回复
热议问题