Insertion sort
Insertion sort is implemented as follows:
First create a new empty list to save the sorted ordered sequence (we call it an "ordered list").
Take out a number from the original sequence and insert it into the "ordered list" so that it remains in an ordered state.
Repeat step 2 until the original number column is empty.
The average time complexity of insertion sort is square, which is not efficient, but easy to implement. It relies on the idea of "gradually expanding the results" to gradually increase the length of the ordered list until its length is equal to the length of the original list.
(Quoted from Baidu Encyclopedia)
javascript code