From 77905d7e9fb09436a53c99b923b528c1e5b061a4 Mon Sep 17 00:00:00 2001 From: Alex Johnson Date: Tue, 25 Nov 2014 14:42:49 -0800 Subject: [PATCH 1/2] Add option for con-splat-enating arrays CoffeeScript allows you to concatenate arrays by splatting them into an array literal. This change adds a section describing that option. --- chapters/arrays/concatenating-arrays.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/chapters/arrays/concatenating-arrays.md b/chapters/arrays/concatenating-arrays.md index df0be98..a023791 100644 --- a/chapters/arrays/concatenating-arrays.md +++ b/chapters/arrays/concatenating-arrays.md @@ -56,6 +56,16 @@ array1 # => [1, 2, 3, 4, 5, 6] {% endhighlight %} +A more idiomatic approach is to use the splat operator (`...`) directly in an array literal. This can be used to concatenate any number of arrays. + +{% highlight coffeescript %} +array1 = [1, 2, 3] +array2 = [4, 5, 6] +array3 = [array1..., array2...] +array3 +# => [1, 2, 3, 4, 5, 6] +{% endhighlight %} + ## Discussion CoffeeScript lacks a special syntax for joining arrays, but `concat()` and `push()` are standard JavaScript methods. From cf6af7220a9abc8a65da196b9f95d911d6221ddb Mon Sep 17 00:00:00 2001 From: Alex Johnson Date: Tue, 25 Nov 2014 14:45:03 -0800 Subject: [PATCH 2/2] Add myself to the authors list I hope that's not too presumptuous for such a small change. --- authors.md | 1 + 1 file changed, 1 insertion(+) diff --git a/authors.md b/authors.md index 70bea43..fe612ef 100644 --- a/authors.md +++ b/authors.md @@ -23,6 +23,7 @@ The following people are totally rad and awesome because they have contributed r * [Anton Rissanen](http://github.com/antris) *hello@anton.fi* * Calum Robertson *http://github.com/randusr836* * Jake Burkhead *https://github.com/jlburkhead* +* [Alex Johnson](https://github.com/nonsensery) * ...You! What are you waiting for? Check out the [contributing](/contributing) section and get cracking! # Developers