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 authors-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ If the answer to either question is no, you might have some code that is a "clev

## What If My Recipe is Inefficient/Too Big/Too Slow?

If it solves a problem to which the alternative is to _not_ solve the problem, share it. Let the reader decide if they want to use it. Sometimes we want tight efficient code, other times we want a robust featureset. If the code has abysmal performance characteristics, be sure to warn the reader in the Discussion.
If it solves a problem to which the alternative is to _not_ solve the problem, share it. Let the reader decide if they want to use it. Sometimes we want tight efficient code, other times we want a robust feature set. If the code has abysmal performance characteristics, be sure to warn the reader in the Discussion.

## Can I Edit An Existing Recipe?

Expand Down
6 changes: 3 additions & 3 deletions chapters/ajax/ajax_request_without_jquery.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ loadDataFromServer = ->
req = new XMLHttpRequest()

req.addEventListener 'readystatechange', ->
if req.readyState is 4 # ReadyState Compelte
if req.readyState is 4 # ReadyState Complete
successResultCodes = [200, 304]
if req.status in successResultCodes
data = eval '(' + req.responseText + ')'
Expand All @@ -69,13 +69,13 @@ We define our loadDataFromServer callback beginning on line 2.

We create a XMLHttpRequest request object (line 3) and add a *readystatechange* event handler. This fires whenever the request's readyState changes.

In the event handler we check to see if the readyState = 4, indicating the request has completed. Then, we check the request status value. Both 200 or 304 represent a succsessful request. Anything else represents an error condition.
In the event handler we check to see if the readyState = 4, indicating the request has completed. Then, we check the request status value. Both 200 or 304 represent a successful request. Anything else represents an error condition.

If the request was indeed successful, we eval the JSON returned from the server and assign it to a data variable. At this point, we can use the returned data in any way we need to.

The last thing we need to do is actually make our request.

Line 13 opens a 'GET' request to retreive the data.json file.
Line 13 opens a 'GET' request to retrieve the data.json file.

Line 14 sends our request to the server.

Expand Down
2 changes: 1 addition & 1 deletion chapters/arrays/filtering-arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ array.filter (x) -> x > 5
# => [6,7,8,9,10]
{% endhighlight %}

In pre-EC5 implementations, extend the Array prototype to add a filter function which will take a callback and perform a comprension over itself, collecting all elements for which the callback is true. Be sure to check if the function is already implemented before overwriting it:
In pre-EC5 implementations, extend the Array prototype to add a filter function which will take a callback and perform a comprehension over itself, collecting all elements for which the callback is true. Be sure to check if the function is already implemented before overwriting it:

{% highlight coffeescript %}
# Extending Array's prototype
Expand Down
2 changes: 1 addition & 1 deletion chapters/arrays/reducing-arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ You have an array of objects and want to reduce them to a value, similar to Ruby

## Solution

You can simply use Array's `reduce()` and `reduceRight()` methods along with an anonoymous function, keeping the code clean and readable. The reduction may be something simple such as using the `+` operator with numbers or strings.
You can simply use Array's `reduce()` and `reduceRight()` methods along with an anonymous function, keeping the code clean and readable. The reduction may be something simple such as using the `+` operator with numbers or strings.

{% highlight coffeescript %}
[1,2,3,4].reduce (x,y) -> x + y
Expand Down
2 changes: 1 addition & 1 deletion chapters/arrays/testing-every-element.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ evens.every (x)-> x % 2 == 0
# => true
{% endhighlight %}

Array.every was addded to Mozilla's Javascript 1.6 and made standard with EcmaScript 5. If you to support browsers that do not implement EC5 then check out [`_.all` from underscore.js][underscore].
Array.every was added to Mozilla's Javascript 1.6 and made standard with ECMAScript 5. If you to support browsers that do not implement EC5 then check out [`_.all` from underscore.js][underscore].

For a real world example, pretend you have a multiple select list that looks like:

Expand Down
2 changes: 1 addition & 1 deletion chapters/arrays/where-for-arrays-of-objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ cats.where name:"bubbles", (a, b) -> "#{ a }".toLowerCase() is "#{ b }".toLowerC
# now it's case insensitive
{% endhighlight %}

it's more a method to deal with collection and it could be rename as "find" but popular libraires like underscore or lodash name it "where".
it's more a method to deal with collection and it could be rename as "find" but popular libraries like underscore or lodash name it "where".
2 changes: 1 addition & 1 deletion chapters/dates_and_times/date-of-thanksgiving.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ chapter: Dates and Times
---
## Problem

You need to calculate when is Thanksgivinig in given year.
You need to calculate when Thanksgiving is in a given year.

## Solution

Expand Down
10 changes: 5 additions & 5 deletions chapters/dates_and_times/days-between-two-dates.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ You need to find how much seconds minutes, hours, days, months or years has pass

## Solution

Use JavaScript's Date function getTime(). Which provides how much time in miliseconds has passed since 01/01/1970:
Use JavaScript's Date function getTime(). Which provides how much time in milliseconds has passed since 01/01/1970:

{% highlight coffeescript %}
DAY = 1000 * 60 * 60 * 24
Expand All @@ -22,12 +22,12 @@ days_passed = Math.round((d2.getTime() - d1.getTime()) / DAY)

## Discussion

Using miliseconds makes the life easier to avoid overflow mistakes with Dates. So we first calculate how much miliseconds has a day.
Then, given two distincit dates, just get the diference in miliseconds betwen two dates and then divide by how much miliseconds has a
Using milliseconds makes the life easier to avoid overflow mistakes with Dates. So we first calculate how much milliseconds has a day.
Then, given two distinct dates, just get the difference in milliseconds between two dates and then divide by how much milliseconds has a
day. It will get you the days between two distinct dates.

If you'd like to calculate the hours between two dates objects you can do that just by dividing the diference in miliseconds by the
convertion of miliseconds to hours. The same goes to minutes and seconds.
If you'd like to calculate the hours between two date objects, you can do that just by dividing the difference in milliseconds by the
conversion of milliseconds to hours. The same goes for minutes and seconds.

{% highlight coffeescript %}
HOUR = 1000 * 60 * 60
Expand Down
2 changes: 1 addition & 1 deletion chapters/dates_and_times/moon-phase-for-date.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ You want to find the current phase of the moon.

## Solution

The following code provides a method to calcualate the phase of the moon for a given date.
The following code provides a method to calculate the phase of the moon for a given date.

{% highlight coffeescript %}
# moonPhase.coffee
Expand Down
2 changes: 1 addition & 1 deletion chapters/design_patterns/adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ In such a situation, the [Adapter Pattern](//en.wikipedia.org/wiki/Adapter_patte
class AwesomeGrid
constructor: (@datasource)->
@sort_order = 'ASC'
@sorter = new NullSorter # in this place we use NullObject pattern (another usefull pattern)
@sorter = new NullSorter # in this place we use NullObject pattern (another useful pattern)
setCustomSorter: (@customSorter) ->
@sorter = customSorter
sort: () ->
Expand Down
4 changes: 2 additions & 2 deletions chapters/design_patterns/observer.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ postOffice.notifyNewItemReleased "Mens Health"
## Discussion

Here you have an observer object (PostOffice) and observable objects (MagazineSubscriber, NewspaperSubscriber).
To be notified about an event of publishing new periodical observable object should make subscribtion on PostOffice.
Every of subscribed objects is stored internaly in the PostOffice array of subscribtions.
To be notified about an event of publishing new periodical observable object should make subscription on PostOffice.
Every of subscribed objects is stored internally in the PostOffice array of subscriptions.
Every subscriber is notified on new concrete periodical is published.
2 changes: 1 addition & 1 deletion chapters/design_patterns/singleton.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Singleton.PrivateClass # => undefined

## Discussion

See in the above example how all instances are outputting from the same instance of the Singleton class. You can also see that the PrivateClass and instance variable are not accessible outside the Singleton class. In essance the Singleton class provides a static method get which returns only one instance of PrivateClass and only one. It also hides the PrivateClass from the world so that you can not create your own.
See in the above example how all instances are outputting from the same instance of the Singleton class. You can also see that the PrivateClass and instance variable are not accessible outside the Singleton class. In essence the Singleton class provides a static method get which returns only one instance of PrivateClass and only one. It also hides the PrivateClass from the world so that you can not create your own.

The idea of hiding or making private the inner workings is preference. Especially since by default CoffeeScript wraps the compiled code inside it's own IIFE (closure) allowing you to define classes without worry that it might be accessible from outside the file. In this example, note that I am using the idiomatic module export feature to emphasize the publicly accessible portion of the module. (See this discussion for further explanation on [exporting to the global namespace][1]).

Expand Down
2 changes: 1 addition & 1 deletion chapters/functions/debounce.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mouseMoveHandler: (e) ->

someOtherHandler: (e) ->
@debounce((e) ->
# Do something here, but only once 250 milliseconds after initial execuction.
# Do something here, but only once 250 milliseconds after initial execution.
250, true)
{% endhighlight %}

Expand Down
2 changes: 1 addition & 1 deletion chapters/functions/parentheses.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if (condition) {

Like Ruby, CoffeeScript allows you to drop parentheses to method calls. Unlike Ruby, however, CoffeeScript treats a bare function name as the pointer to the function. The practical upshot of this is that if you give no arguments to a method, CoffeeScript cannot tell if you want to call the function or use it as a reference.

Is this good or bad? It's just different. It creates an unexpected syntax case -- parentheses aren't _always_ optional -- but in exchange it gives you the ability to pass and receive functions fluently by name, something that's a bit klunky in Ruby.
Is this good or bad? It's just different. It creates an unexpected syntax case -- parentheses aren't _always_ optional -- but in exchange it gives you the ability to pass and receive functions fluently by name, something that's a bit clunky in Ruby.

This usage of the do-notation is a neat approach for CoffeeScript with parenphobia.
Some people simply prefer to write out the parentheses in the function call, though.
2 changes: 1 addition & 1 deletion chapters/math/fast-fibonacci.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This CoffeeScript Javascript Fast Fibonacci code is
based on the python code from Robin Houston's blog.
See below links.

A few things I want to introduce in time are implementions of
A few things I want to introduce in time are implementations of
Newtonian, Burnikel / Ziegler, and Binet's algorithms on top
of a Big Number framework.

Expand Down
12 changes: 6 additions & 6 deletions chapters/math/fast-inv-square.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ In this CoffeeScript variant I supply the original classic, and newer optimal
sized magic number.

Another feature included is the ability to alter the level of precision.
This is done by controling the number of iterations for performing [Newton's
This is done by controlling the number of iterations for performing [Newton's
method][3].

Depending on the machine and level of percision this algorithm may still
Depending on the machine and level of precision this algorithm may still
provide performance increases over the classic.

To run this, compile the script with coffee:
coffee -c script.coffee

Then copy & paste the compiled js code in to the JavaSript console of your
Then copy & paste the compiled js code in to the JavaScript console of your
browser.

Note: You will need a browser which supports [typed-arrays][4].
Expand Down Expand Up @@ -63,16 +63,16 @@ In this CoffeeScript variant I supply the original classic, and newer optimal
sized magic number.

Another feature included is the ability to alter the level of precision.
This is done by controling the number of iterations for performing Newton's
This is done by controlling the number of iterations for performing Newton's
method[3].

Depending on the machine and level of percision this algorithm may still
Depending on the machine and level of precision this algorithm may still
provide performance increases over the classic.

To run this, compile the script with coffee:
coffee -c <this script>.coffee

Then copy & paste the compiled js code in to the JavaSript console of your
Then copy & paste the compiled js code in to the JavaScript console of your
browser.

Note: You will need a browser which supports typed-arrays[4].
Expand Down
2 changes: 1 addition & 1 deletion chapters/math/generating-random-numbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ range = Math.random() * (max - min) + min

This is a straight lift from JavaScript.

Note that JavaScripts's Math.random() does not allow you to seed the random number generator to force certain values. See [Generating Predictable Random Numbers](/chapters/math/generating-predictable-random-numbers) for that.
Note that JavaScript's Math.random() does not allow you to seed the random number generator to force certain values. See [Generating Predictable Random Numbers](/chapters/math/generating-predictable-random-numbers) for that.

To generate a number from 0 up to (but not including) n, multiply by n. To generate a number from 1 to n (inclusive), multiply by n and add 1.
2 changes: 1 addition & 1 deletion chapters/strings/capitalizing-words.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Or do the same thing using a list comprehension:

## Discussion

Split, map, join is a common scripting pattern dating back to perl. This function may benefit from being placed directly onto the String class by [Extending Classes](/chapters/objects/extending-classes).
Split, map, join is a common scripting pattern dating back to Perl. This function may benefit from being placed directly onto the String class by [Extending Classes](/chapters/objects/extending-classes).

Be aware that two wrinkles can appear in the split, map, join pattern. The first is that the split text works best when it is constant. If the source string has multiple spaces in it, the split will need to take this into account to prevent getting extra, empty words. One way to do this is with a regular expression to split on runs of whitespace instead of a single space:

Expand Down
6 changes: 3 additions & 3 deletions wanted-recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ title: Wanted Recipes

Here's a list of recipes we think we need. Pick one, implement it, and remove it from the page. Alternately, add a quick note here for a recipe you'd like to see so someone else can add it.

In the notes below, "JS" means the recipe is just a simple passthrough to an existing JavaScript method.
In the notes below, "JS" means the recipe is just a simple pass-through to an existing JavaScript method.

## Syntax

* Ensuring variables are closed over # with "do"

## Strings

* HTML methods # JS .sup(), .sub(), .blink(), .link(url), etc. May not exist in your JS impl!
* HTML methods # JS .sup(), .sub(), .blink(), .link(url), etc. May not exist in your JS implementation!
* substr
{% highlight coffeescript %}
str.substr(x,y) === str[x..x+y-1] === str[x...x+y]
Expand Down Expand Up @@ -48,7 +48,7 @@ evens.every even
* Logarithms # Math.log
* Finding the base-n log # Math.log(num) / Math.log(base)
* Exponents # Math.exp
* Check if a creditcard is valid (checksum, Luhn algorithm)
* Check if a credit card is valid (checksum, Luhn algorithm)

## Functions

Expand Down