All examples now compile and lint cleanly.

This commit is contained in:
Jeremy Ashkenas 2010-10-24 21:37:27 -04:00
parent 343c0fdef7
commit 99c06b5cda
4 changed files with 6 additions and 6 deletions

View File

@ -3,7 +3,7 @@
runtime = (N) ->
[sum, t] = [0, 0]
for n in [1..N]
for n from 1 to N
sum += 2 * t
t = n - 1 + sum / n
t

View File

@ -1,7 +1,7 @@
# 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]
for i from 0 to list.length - 1
for j from 0 to list.length - i - 1
[list[j], list[j+1]] = [list[j+1], list[j]] if list[j] > list[j+1]
list

View File

@ -7,7 +7,7 @@ is_valid_identifier = (identifier) ->
sum = 0
alt = false
for i in [(identifier.length - 1)..0]
for i from identifier.length - 1 to 0 by -1
# Get the next digit.
num = parseInt identifier.charAt(i), 10

View File

@ -3,13 +3,13 @@ selection_sort = (list) ->
len = list.length
# For each item in the list.
for i in [0...len]
for i from 0 to len - 1
# Set the minimum to this position.
min = i
# Check the rest of the array to see if anything is smaller.
(min = j if list[j] < list[min]) for j in [(i+1)...len]
min = j if list[j] < list[min] for j from i + 1 to len - 1
# Swap if a smaller item has been found.
[list[i], list[min]] = [list[min], list[i]] if i isnt min