Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chapters/arrays/concatenating-arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Use JavaScript's Array concat() method:
{% highlight coffeescript %}
ray1 = [1,2,3]
ray2 = [4,5,6]
ray3 = ray1.concat(ray2)
ray3 = ray1.concat ray2
# => [1, 2, 3, 4, 5, 6]
{% endhighlight %}

Expand Down
2 changes: 1 addition & 1 deletion chapters/arrays/max-array-value.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ In ECMAScript 5, use `Array#reduce`. In older javascripts, use Math.max over a l

{% highlight coffeescript %}
# ECMAScript 5
[12,32,11,67,1,3].reduce (a,b) -> Math.max(a,b)
[12,32,11,67,1,3].reduce (a,b) -> Math.max a, b
# => 67

# Pre-EC5
Expand Down
10 changes: 5 additions & 5 deletions chapters/math/fast-fibonacci.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ fib_bits = (n) ->

bits = []
while n > 0
[n, bit] = divmodBasic(n, 2)
bits.push(bit)
[n, bit] = divmodBasic n, 2
bits.push bit

bits.reverse()
return bits
Expand All @@ -67,7 +67,7 @@ fibFast = (n) ->

[a, b, c] = [1, 0, 1]

for bit in fib_bits(n)
for bit in fib_bits n
if bit
[a, b] = [(a+c)*b, b*b + c*c]
else
Expand All @@ -88,12 +88,12 @@ divmodBasic = (x, y) ->
Burnikel / Ziegler _if_ possible...
###

return [(q = Math.floor(x/y)), (r = if x < y then x else x % y)]
return [(q = Math.floor x/y), (r = if x < y then x else x % y)]

start = (new Date).getTime();
calc_value = fibFast(MAXIMUM_JS_FIB_N)
diff = (new Date).getTime() - start;
console.log("[#{calc_value}] took #{diff} ms.")
console.log "[#{calc_value}] took #{diff} ms."
{% endhighlight %}

## Discussion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Use `::` to detect the function, and assign to it if it does not exist.
{% highlight coffeescript %}
unless Array::filter
Array::filter = (callback) ->
element for element in this when callback(element)
element for element in this when callback element

array = [1..10]

Expand Down
8 changes: 4 additions & 4 deletions chapters/strings/finding-substrings.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ You need to find the first or last occurrence of a search string within a messag
## Solution

Use Javascript's indexOf() and lastIndexOf() to find the first and last occurrences of a string, respectively.
Syntax: string.indexOf(searchstring, start)
Syntax: string.indexOf searchstring, start

{% highlight coffeescript %}
message = "This is a test string. This has a repeat or two. This might even have a third."
message.indexOf("This",0)
message.indexOf "This", 0
# => 0

# Modifying the start parameter
message.indexOf("This",5)
message.indexOf "This", 5
# => 23

message.lastIndexOf("This")
message.lastIndexOf "This"
# => 49

{% endhighlight %}
Expand Down
2 changes: 1 addition & 1 deletion chapters/strings/repeating.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Create an array of n+1 nulls, and then join it with the repetition string as the

{% highlight coffeescript %}
# create a string of 10 foos
Array(11).join('foo')
Array(11).join 'foo'

# => "foofoofoofoofoofoofoofoofoofoo"
{% endhighlight %}
Expand Down