Function insertionSort

挿入ソートを使用して配列をソート

const numbers = [4, 2, 7, 1, 3];
insertionSort(numbers); // [1, 2, 3, 4, 7]
const numbers = [4, 2, 7, 1, 3];
insertionSort(numbers, (a, b) => a - b); // [1, 2, 3, 4, 7]
const numbers = [4, 2, 7, 1, 3];
insertionSort(numbers, undefined, 1, 3); // [4, 1, 2, 7, 3]
  • Type Parameters

    • T

    Parameters

    • array: T[]

      ソートする配列

    • compareFunction: (a: T, b: T) => number = ...

      比較関数

    • start: number = 0

      ソートを開始する配列のインデックス

    • end: number = ...

      ソートを終了する配列のインデックス

    Returns T[]

    ソートされた配列