From 3d624a3ada5c7e61da7630a07ece183308cf790e Mon Sep 17 00:00:00 2001 From: Mohammad Aidid Bin Mohd Jaafar Date: Tue, 4 Oct 2011 01:23:26 +0800 Subject: [PATCH 1/3] Added a new recipe for define range in an array using CoffeeScript --- chapters/arrays/define-ranges.md | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 chapters/arrays/define-ranges.md diff --git a/chapters/arrays/define-ranges.md b/chapters/arrays/define-ranges.md new file mode 100644 index 0000000..a96d49a --- /dev/null +++ b/chapters/arrays/define-ranges.md @@ -0,0 +1,47 @@ +--- +layout: recipe +title: Define Ranges Array +chapter: Arrays +--- +## Problem + +You want to define range in array. + +## Solution + +There are two method to define range of an array element in CoffeeScript. + +{% highlight coffeescript %} + +myArray = [1..10] +# => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] + +{% endhighlight %} + +{% highlight coffeescript %} + +myArray = [1...10] +# => [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] + +{% endhighlight %} + +We can also reverse the range of element by writing it this way. + +{% highlight coffeescript %} + +myLargeArray = [10..1] +# => [ 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 ] + +{% endhighlight %} + +{% highlight coffeescript %} +myLargeArray = [10...1] +# => [ 10, 9, 8, 7, 6, 5, 4, 3, 2 ] + +{% endhighlight %} + +## Discussion + +Inclusive range always define by '..' operator. + +Exclusive range difine by '...', and always omit the last value. From febe194dd0f16171c1a1b5b69bdd2a551c2875a9 Mon Sep 17 00:00:00 2001 From: Mohammad Aidid Bin Mohd Jaafar Date: Tue, 4 Oct 2011 03:07:09 +0800 Subject: [PATCH 2/3] Fixed spelling error 'difine' to 'define' --- chapters/arrays/define-ranges.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapters/arrays/define-ranges.md b/chapters/arrays/define-ranges.md index a96d49a..9adabcc 100644 --- a/chapters/arrays/define-ranges.md +++ b/chapters/arrays/define-ranges.md @@ -44,4 +44,4 @@ myLargeArray = [10...1] Inclusive range always define by '..' operator. -Exclusive range difine by '...', and always omit the last value. +Exclusive range define by '...', and always omit the last value. From 8e3bf94c6ad4af278f92336a438bcd52190dc15f Mon Sep 17 00:00:00 2001 From: Mohammad Aidid Bin Mohd Jaafar Date: Tue, 4 Oct 2011 03:14:17 +0800 Subject: [PATCH 3/3] Fixed spelling mistakes and edit the problem statement sentence and solution sentence to reflect codes intention --- chapters/arrays/define-ranges.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chapters/arrays/define-ranges.md b/chapters/arrays/define-ranges.md index 9adabcc..8296e09 100644 --- a/chapters/arrays/define-ranges.md +++ b/chapters/arrays/define-ranges.md @@ -5,11 +5,11 @@ chapter: Arrays --- ## Problem -You want to define range in array. +You want to define a range in an array. ## Solution -There are two method to define range of an array element in CoffeeScript. +There are two ways to define a range of array elements in CoffeeScript. {% highlight coffeescript %}