Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function insertionSort(array) {
  for (let i = 0; i < array.length; i++) {
    let temp = array[i]
    let j = i - 1
    while (j >= 0 && array[j] > temp) {
      array[j + 1] = array[j]
      j--
    }
    array[j + 1] = temp
  }
  return array
}

insertionSort([9, 5, 10, 8, 2])
node v10.15.2 linux/amd64