Bubble sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent pairs and swaps them if they are in the wrong order.
The pass through the list is repeated until the list is sorted. The algorithm, which is a comparison sort, is named for the way smaller or larger elements "bubble" to the top of the list.
bubbleSort(array)
should return the origin array
, sorted with bubble sort.
Example:
bubbleSort([5, 3, 8, 2, 1, 4]) // [1, 2, 3, 4, 5, 8]