adding soaked method calls, with caching

This commit is contained in:
Jeremy Ashkenas
2010-01-24 12:52:15 -05:00
parent d728c3d669
commit 817e8deb27
6 changed files with 63 additions and 4 deletions

View File

@@ -0,0 +1,11 @@
# 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.
print(bubble_sort([3, 2, 1]).join(' ') is '1 2 3')
print(bubble_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9')