Skip to content

Commit

Permalink
Updating examples for 0.9.5
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Nov 21, 2010
1 parent 710290a commit 8fcd67e
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion documentation/coffee/range_comprehensions.coffee
@@ -1,2 +1,2 @@
count = (num for num from 1 to 10)
countdown = (num for num in [10..1])

2 changes: 1 addition & 1 deletion examples/beautiful_code/quicksort_runtime.coffee
Expand Up @@ -3,7 +3,7 @@

runtime = (N) ->
[sum, t] = [0, 0]
for n from 1 to N
for n in [1..N]
sum += 2 * t
t = n - 1 + sum / n
t
Expand Down
4 changes: 2 additions & 2 deletions examples/computer_science/bubble_sort.coffee
@@ -1,7 +1,7 @@
# A bubble sort implementation, sorting the given array in-place.
bubble_sort = (list) ->
for i from 0 to list.length - 1
for j from 0 to list.length - i - 1
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

Expand Down
2 changes: 1 addition & 1 deletion examples/computer_science/luhn_algorithm.coffee
Expand Up @@ -7,7 +7,7 @@ is_valid_identifier = (identifier) ->
sum = 0
alt = false

for i from identifier.length - 1 to 0 by -1
for i in [identifier.length - 1..0] by -1

# Get the next digit.
num = parseInt identifier.charAt(i), 10
Expand Down
4 changes: 2 additions & 2 deletions examples/computer_science/selection_sort.coffee
Expand Up @@ -3,13 +3,13 @@ selection_sort = (list) ->
len = list.length

# For each item in the list.
for i from 0 to len - 1
for i in [0...len]

# 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 from i + 1 to len - 1
min = j if list[j] < list[min] for j in [i + 1...len]

# Swap if a smaller item has been found.
[list[i], list[min]] = [list[min], list[i]] if i isnt min
Expand Down
4 changes: 2 additions & 2 deletions examples/potion.coffee
Expand Up @@ -2,7 +2,7 @@

# 5 times: "Odelay!" print.

print "Odelay!" for i from 1 to 5
print "Odelay!" for i in [1..5]


# add = (x, y): x + y.
Expand Down Expand Up @@ -166,7 +166,7 @@ while count > 0
# 1 to 5 (a):
# a string print.

print a for a from 1 to 5
print a for a in [1..5]


# if (3 ?gender):
Expand Down
10 changes: 5 additions & 5 deletions examples/underscore.coffee
Expand Up @@ -83,9 +83,9 @@ _.each = (obj, iterator, context) ->
if nativeForEach and obj.forEach is nativeForEach
obj.forEach iterator, context
else if _.isNumber obj.length
iterator.call(context, obj[i], i, obj) for i from 0 to obj.length - 1
iterator.call context, obj[i], i, obj for i in [0...obj.length]
else
iterator.call(context, val, key, obj) for key, val of obj
iterator.call context, val, key, obj for key, val of obj
catch e
throw e if e isnt breaker
obj
Expand Down Expand Up @@ -311,7 +311,7 @@ _.intersect = (array) ->
_.zip = ->
length = _.max _.pluck arguments, 'length'
results = new Array length
for i from 0 to length - 1
for i in [0...length]
results[i] = _.pluck arguments, String i
results

Expand Down Expand Up @@ -410,7 +410,7 @@ _.compose = ->
funcs = arguments
->
args = arguments
for i from funcs.length - 1 to 0 by -1
for i in [funcs.length - 1..0] by -1
args = [funcs[i].apply(this, args)]
args[0]

Expand Down Expand Up @@ -562,7 +562,7 @@ _.identity = (value) -> value

# Run a function `n` times.
_.times = (n, iterator, context) ->
iterator.call(context, i) for i from 0 to n - 1
iterator.call context, i for i in [0...n]


# Break out of the middle of an iteration.
Expand Down

0 comments on commit 8fcd67e

Please sign in to comment.