diff --git a/chapters/arrays/concatenating-arrays.md b/chapters/arrays/concatenating-arrays.md index b6fcd13..af614ac 100644 --- a/chapters/arrays/concatenating-arrays.md +++ b/chapters/arrays/concatenating-arrays.md @@ -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 %} diff --git a/chapters/arrays/max-array-value.md b/chapters/arrays/max-array-value.md index ab8cb70..537344c 100644 --- a/chapters/arrays/max-array-value.md +++ b/chapters/arrays/max-array-value.md @@ -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 diff --git a/chapters/math/fast-fibonacci.md b/chapters/math/fast-fibonacci.md index b8f7027..9c285bb 100644 --- a/chapters/math/fast-fibonacci.md +++ b/chapters/math/fast-fibonacci.md @@ -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 @@ -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 @@ -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 diff --git a/chapters/metaprogramming/detecting-and-replacing-functions.md b/chapters/metaprogramming/detecting-and-replacing-functions.md index d448a41..6a99931 100644 --- a/chapters/metaprogramming/detecting-and-replacing-functions.md +++ b/chapters/metaprogramming/detecting-and-replacing-functions.md @@ -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] diff --git a/chapters/strings/finding-substrings.md b/chapters/strings/finding-substrings.md index 1bebca9..a33af8c 100644 --- a/chapters/strings/finding-substrings.md +++ b/chapters/strings/finding-substrings.md @@ -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 %} diff --git a/chapters/strings/repeating.md b/chapters/strings/repeating.md index 7749444..2df0c3c 100644 --- a/chapters/strings/repeating.md +++ b/chapters/strings/repeating.md @@ -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 %}