Sha256: f0b27850ca151fdec40fe31f294ccf470ba38b7af61291a0ca1232e5f602c906
Contents?: true
Size: 364 Bytes
Versions: 7
Compression:
Stored size: 364 Bytes
Contents
# A bubble sort implementation, sorting the given array in-place. bubble_sort: (list) -> for i in [0...list.length] for j in [0...list.length - i] [list[j], list[j+1]]: [list[j+1], list[j]] if list[j] > list[j+1] list # Test the function. puts(bubble_sort([3, 2, 1]).join(' ') is '1 2 3') puts(bubble_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9')
Version data entries
7 entries across 7 versions & 1 rubygems