Updating examples for 0.9.5

This commit is contained in:
Jeremy Ashkenas 2010-11-21 11:41:24 -05:00
parent 710290ad1d
commit 8fcd67e82f
7 changed files with 14 additions and 14 deletions

View File

@ -1,2 +1,2 @@
count = (num for num from 1 to 10)
countdown = (num for num in [10..1])

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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.
@ -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):

View File

@ -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
@ -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
@ -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]
@ -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.