From 2228b639d6e1b06cdb9d15b4a18aa1e971e9b0cf Mon Sep 17 00:00:00 2001 From: Devin Weaver Date: Tue, 8 Oct 2013 00:48:21 -0400 Subject: [PATCH 01/57] Changed to best practice of the `this` keyword I've seen several people on IRC talk about readability. It seems there is some opinions that when chaining like this the `this` keyword is more readable then a dangling `@` symbol. I think it is a good idea to offer code readability in this project. Feel free to revert this commit if this is disputed. (Unable to open a PR from in the Github UI). --- chapters/classes_and_objects/chaining.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chapters/classes_and_objects/chaining.md b/chapters/classes_and_objects/chaining.md index 65f450f..be19212 100644 --- a/chapters/classes_and_objects/chaining.md +++ b/chapters/classes_and_objects/chaining.md @@ -20,13 +20,13 @@ class CoffeeCup sugar: false strength: (newStrength) -> @properties.strength = newStrength - @ + this cream: (newCream) -> @properties.cream = newCream - @ + this sugar: (newSugar) -> @properties.sugar = newSugar - @ + this morningCup = new CoffeeCup() From 5358690140a8d0a8efffe43cf3bac8ccb2857e06 Mon Sep 17 00:00:00 2001 From: Stephen Daves Date: Tue, 22 Oct 2013 23:20:23 -0600 Subject: [PATCH 02/57] Remove unneeded word --- chapters/design_patterns/singleton.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/design_patterns/singleton.md b/chapters/design_patterns/singleton.md index 18bbf27..6aff70c 100644 --- a/chapters/design_patterns/singleton.md +++ b/chapters/design_patterns/singleton.md @@ -12,7 +12,7 @@ Many times you only want one, and only one, instance of a class. For example, yo The publicly available class only contains the method to get the one true instance. The instance is kept within the closure of that public object and is always returned. -This is works because CoffeeScript allows you to define executable statements inside a class definition. However, because most CoffeeScript compiles into a [IIFE][] wrapper you do not have to place the private class inside the class definition if this style suits you. The later might be useful when developing modular code such as found in [CommonJS][] (Node.js) or [Require.js][] (See the discussion for an example). +This works because CoffeeScript allows you to define executable statements inside a class definition. However, because most CoffeeScript compiles into a [IIFE][] wrapper you do not have to place the private class inside the class definition if this style suits you. The later might be useful when developing modular code such as found in [CommonJS][] (Node.js) or [Require.js][] (See the discussion for an example). [IIFE]: http://benalman.com/news/2010/11/immediately-invoked-function-expression/ [CommonJS]: http://www.commonjs.org/ From 2cc50bce27bbd9f70341678c6acf3c565ed255b9 Mon Sep 17 00:00:00 2001 From: Orban Botond Date: Sun, 3 Nov 2013 15:48:40 +0200 Subject: [PATCH 03/57] FIX #95 --- chapters/arrays/testing-every-element.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/arrays/testing-every-element.md b/chapters/arrays/testing-every-element.md index 5978500..4f82c2a 100644 --- a/chapters/arrays/testing-every-element.md +++ b/chapters/arrays/testing-every-element.md @@ -12,7 +12,7 @@ You want to be able to check that every element in an array meets a particular c Use Array.every (ECMAScript 5): {% highlight coffeescript %} -evens = (x for x in [1..10] by 2) +evens = (x for x in [0..10] by 2) evens.every (x)-> x % 2 == 0 # => true From 2d16a576acd38b3666737d4861aca87652ee3502 Mon Sep 17 00:00:00 2001 From: jlburkhead Date: Sun, 15 Dec 2013 04:49:15 -0500 Subject: [PATCH 04/57] add an example of generating random numbers in an arbitrary range --- chapters/math/generating-random-numbers.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/chapters/math/generating-random-numbers.md b/chapters/math/generating-random-numbers.md index f181940..afb1c5c 100644 --- a/chapters/math/generating-random-numbers.md +++ b/chapters/math/generating-random-numbers.md @@ -24,6 +24,12 @@ percentile = Math.floor(Math.random() * 100) dice = Math.floor(Math.random() * 6) + 1 1 <= dice <= 6 # => true + +max = 42 +min = -13 +range = Math.random() * (max - min) + min +-13 <= range < 42 +# => true {% endhighlight %} ## Discussion From dd4f0b9ea9a60ba4b3d31abe34f92f643074a129 Mon Sep 17 00:00:00 2001 From: jlburkhead Date: Sun, 15 Dec 2013 05:06:33 -0500 Subject: [PATCH 05/57] add recipe on exponents and logarithms --- .../working-with-exponents-and-logarithms.md | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 chapters/math/working-with-exponents-and-logarithms.md diff --git a/chapters/math/working-with-exponents-and-logarithms.md b/chapters/math/working-with-exponents-and-logarithms.md new file mode 100644 index 0000000..6891530 --- /dev/null +++ b/chapters/math/working-with-exponents-and-logarithms.md @@ -0,0 +1,37 @@ +--- +layout: recipe +title: Working with Exponents and Logarithms +chapter: Math +--- +## Problem + +You need to do some calculations that involve exponents and logarithms. + +## Solution + +Use Javascript's Math object to provide common mathematical functions. + +{% highlight coffeescript %} +# Math.pow(x, y) returns x^y +Math.pow(2, 4) +# => 16 + +# Math.exp(x) returns E^x and is shorthand for Math.pow(Math.E, x) +Math.exp(2) +# => 7.38905609893065 + +# Math.log returns the natural (base E) log +Math.log(5) +# => 1.6094379124341003 +Math.log(Math.exp(42)) +# => 42 + +# To get a log with some other base n, divide by Math.log(n) +Math.log(100) / Math.log(10) +# => 2 + +{% endhighlight %} + +## Discussion + +For more information on the Math object see the documentation on the [Mozilla Developer Netword](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math). Also refer to [Converting Radians and Degrees](/chapters/math/radians-degrees) for discussion of the various constants in the Math object. From 658abba3357ff67286019b5a376a0642be341ca3 Mon Sep 17 00:00:00 2001 From: jlburkhead Date: Sun, 15 Dec 2013 15:10:48 -0500 Subject: [PATCH 06/57] fix another typo and link to correct reference --- authors.md | 1 + chapters/math/working-with-exponents-and-logarithms.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/authors.md b/authors.md index 7876aa2..70bea43 100644 --- a/authors.md +++ b/authors.md @@ -22,6 +22,7 @@ The following people are totally rad and awesome because they have contributed r * Mike Hatfield *oakraven13@gmail.com* * [Anton Rissanen](http://github.com/antris) *hello@anton.fi* * Calum Robertson *http://github.com/randusr836* +* Jake Burkhead *https://github.com/jlburkhead* * ...You! What are you waiting for? Check out the [contributing](/contributing) section and get cracking! # Developers diff --git a/chapters/math/working-with-exponents-and-logarithms.md b/chapters/math/working-with-exponents-and-logarithms.md index 6891530..c8e7c49 100644 --- a/chapters/math/working-with-exponents-and-logarithms.md +++ b/chapters/math/working-with-exponents-and-logarithms.md @@ -34,4 +34,4 @@ Math.log(100) / Math.log(10) ## Discussion -For more information on the Math object see the documentation on the [Mozilla Developer Netword](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math). Also refer to [Converting Radians and Degrees](/chapters/math/radians-degrees) for discussion of the various constants in the Math object. +For more information on the Math object see the documentation on the [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math). Also refer to [Math Constants](/chapters/math/constants) for discussion of the various constants in the Math object. From 3ff4351575f1dd89e9689a8b78ab7710a0e44961 Mon Sep 17 00:00:00 2001 From: Ayush Gupta Date: Tue, 18 Mar 2014 17:20:15 +0530 Subject: [PATCH 07/57] updated string interpolation to mention that it works only with double quoted strings --- chapters/strings/interpolation.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chapters/strings/interpolation.md b/chapters/strings/interpolation.md index b1e1e9e..a437be4 100644 --- a/chapters/strings/interpolation.md +++ b/chapters/strings/interpolation.md @@ -11,7 +11,8 @@ CoffeeScript Variable. ## Solution Use CoffeeScript's ruby-like string interpolation instead of -JavaScript's string addition. +JavaScript's string addition. You must use Double-quoted strings to +allow for interpolation. Single-quoted strings are treated as literals. Interpolation: From dc70747b1a4e8679f975b424311ed9ea08943412 Mon Sep 17 00:00:00 2001 From: Marc Bodmer Date: Sat, 29 Mar 2014 16:43:43 -0400 Subject: [PATCH 08/57] Remove completed recipes for wanted recipes documentation --- wanted-recipes.md | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/wanted-recipes.md b/wanted-recipes.md index 64eec51..5adc15d 100644 --- a/wanted-recipes.md +++ b/wanted-recipes.md @@ -8,16 +8,10 @@ Here's a list of recipes we think we need. Pick one, implement it, and remove it In the notes below, "JS" means the recipe is just a simple passthrough to an existing JavaScript method. -## Introduction - -We need a better introduction. Right now the first recipe is [Embedding JavaScript](/chapters/syntax/embedding_javascript), which doesn't set the right first impression. How about three or four recipes that hold new users' hands a bit more as the first section? - ## Syntax * Ensuring variables are closed over # with "do" -## Objects - ## Strings * HTML methods # JS .sup(), .sub(), .blink(), .link(url), etc. May not exist in your JS impl! @@ -45,10 +39,6 @@ evens.every even [1..10].some (x) -> x % 2 == 0 # => true {% endhighlight %} -## Dates and Times - -* Empty - ## Math * square root # JS Math.sqrt @@ -89,24 +79,11 @@ foo 1, 2, 3 # => 6 {% endhighlight %} -## jQuery - -## Regular Expressions - -## Networking - -* Streaming HTTP server -* Streaming HTTP client - -## AJAX - -* Getting data from a remote server # using raw XHTTPRequest instead of jQuery's `$.ajax` - ## Design patterns * Creational Patterns * Abstract Factory - * Prototype + * Prototype * Structural Patterns * Adapter From 6fe6cce0b1776795f516415fced927fab29e2c8a Mon Sep 17 00:00:00 2001 From: Simon Taranto Date: Wed, 2 Apr 2014 10:42:38 -0700 Subject: [PATCH 09/57] Remove duplicate words --- chapters/regular_expressions/searching-for-substrings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/regular_expressions/searching-for-substrings.md b/chapters/regular_expressions/searching-for-substrings.md index 1928591..888c774 100644 --- a/chapters/regular_expressions/searching-for-substrings.md +++ b/chapters/regular_expressions/searching-for-substrings.md @@ -23,7 +23,7 @@ match = /sample/i.test("Sample text") # => true {% endhighlight %} -The next way to is to call the `exec` method on a `RegExp` pattern or object. The `exec` method returns an array an array with the match information or `null`: +The next way to is to call the `exec` method on a `RegExp` pattern or object. The `exec` method returns an array with the match information or `null`: {% highlight coffeescript %} match = /s(amp)le/i.exec "Sample text" From 552577922c2209b10ae250926ceb71eb5a4eeb4d Mon Sep 17 00:00:00 2001 From: rdubigny Date: Sat, 5 Apr 2014 17:17:15 +0200 Subject: [PATCH 10/57] Change folder name "tests" -> "test" I just lost one hour because of that. --- chapters/testing/testing_with_nodeunit.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/testing/testing_with_nodeunit.md b/chapters/testing/testing_with_nodeunit.md index 30af5b8..ec610d2 100644 --- a/chapters/testing/testing_with_nodeunit.md +++ b/chapters/testing/testing_with_nodeunit.md @@ -17,7 +17,7 @@ For example, we expect our calculator will be able to add and subtract and will {% highlight coffeescript %} -# tests/calculator.test.coffee +# test/calculator.test.coffee Calculator = require '../calculator' From 91e7d3eb8a49a124896fc3101cd4bd0195928e61 Mon Sep 17 00:00:00 2001 From: Joseph Chiocchi Date: Mon, 7 Apr 2014 17:08:07 -0500 Subject: [PATCH 11/57] fix typo on testing-every-element.md --- chapters/arrays/testing-every-element.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/arrays/testing-every-element.md b/chapters/arrays/testing-every-element.md index 4f82c2a..12b78a1 100644 --- a/chapters/arrays/testing-every-element.md +++ b/chapters/arrays/testing-every-element.md @@ -20,7 +20,7 @@ evens.every (x)-> x % 2 == 0 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]. -For a real world example, prentend you have a multiple select list that looks like: +For a real world example, pretend you have a multiple select list that looks like: {% highlight html %}