Sha256: 50730ea49c1f7f136030b35d713b811fa3395cdefab425c969f17c7a38ab1f49
Contents?: true
Size: 378 Bytes
Versions: 10
Compression:
Stored size: 378 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. console.log bubble_sort([3, 2, 1]).join(' ') is '1 2 3' console.log bubble_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9'
Version data entries
10 entries across 10 versions & 2 rubygems