Skip to content

Add a splat technique to concatenating arrays #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 12, 2012
Merged
Changes from 1 commit
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
Next Next commit
Add a splat technique to concatenating arrays
The article lacked any mention of the CoffeeScript's splat, which is more concise than prototype.apply.
  • Loading branch information
Bryce Culhane committed Aug 29, 2012
commit 9d10d31bfbfab720e1a0d7d99074d898b3f7a1b5
10 changes: 10 additions & 0 deletions chapters/arrays/concatenating-arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ array1
# => [1, 2, 3, 4, 5, 6]
{% endhighlight %}

Alternatively, we can pass a CoffeeScript splat (`array2...`) directly into `push()`, avoiding the Array prototype.

{% highlight coffeescript %}
array1 = [1, 2, 3]
array2 = [4, 5, 6]
array1.push array2...
array1
# => [1, 2, 3, 4, 5, 6]
{% endhighlight %}

## Discussion

CoffeeScript lacks a special syntax for joining arrays, but `concat()` and `push()` are standard JavaScript methods.