Sorting arrays using for loop in Javascript

前端 未结 6 1037
灰色年华
灰色年华 2021-01-15 16:36

Is it possible to sort arrays in ascending/descending order using the for loop JavaScript?

I\'ve been learning JS going through a few practice quest

6条回答
  •  南笙
    南笙 (楼主)
    2021-01-15 16:58

    Sure it's possible. First you should decide which algorithm you want to sort with. See here for some great visual examples http://www.sorting-algorithms.com/

    From your example though, you'll need another for loop. So far you're finding the biggest, you'll need another loop to repeat your logic, but find the second biggest, than third, than 4th. etc.

提交回复
热议问题