Skip to content

Latest commit

 

History

History
35 lines (23 loc) · 877 Bytes

SelectionSort.md

File metadata and controls

35 lines (23 loc) · 877 Bytes

Sort.SelectionSort

SelectionSort(array, [comparator], [step])

A SelectionSort algorithm

The sort works by iterating through the array starting from the beginning. Each item is compared to every subsequent item in the array to determine which is smaller. Either the current item is kept or a smaller item is swapped into its spot. This repeats until the order of items is arranged from smallest-to-largest.

Arguments

  1. array (*[]): the input array
  2. [comparator] (Function): a function to compare 2 values *(defaults asc->desc)*
  3. [step] (Function): an optional function that gets applied at each step

Returns

(*): the sorted array