Skip to content

Commit ff52977

Browse files
committed
Fix texts for Array units 1-3
1 parent 153f118 commit ff52977

File tree

5 files changed

+62
-62
lines changed

5 files changed

+62
-62
lines changed

4_Arrays/1_Creating_Arrays/solution_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def array_defined_with_new?(variable, statement)
6666
expect(@values.include?(Float)).to be true
6767
end
6868

69-
it 'holdd a Boolean' do
69+
it 'holds a Boolean' do
7070
included = @values.include?(TrueClass) || @values.include?(FalseClass)
7171
expect(included).to be true
7272
end

4_Arrays/1_Creating_Arrays/task.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The index can be used to access the objects in an Array. You will learn more
2020
about using the index in the next unit "Accessing elements".
2121

2222
An Array can hold all kinds of Ruby objects, such as Strings, Numbers, Booleans,
23-
other Arrays, etc. The objects in an Array don‘t need to be of the same type:
23+
other Arrays, etc. The objects in an Array don‘t need to be of the same type.
2424
An Array can hold all kinds of different objects (e.g. Strings, and Numbers) at the same time.
2525

2626
Let‘s create some Arrays!
@@ -32,12 +32,13 @@ The shortest is surrounding a comma-separated list of objects with square bracke
3232

3333
` [1, 'Mary', true]` *# => [1, "Mary", true]*
3434

35-
An Array is a Ruby object itself. If you ask for an Array‘s class with the `class` method:
35+
An Array is a Ruby object itself. If you ask for an Array‘s class with the `class` method
36+
you will get `Array`:
3637

3738
` numbers = [1, 2, 3]`
3839
` numbers.class` *# => Array*
3940

40-
you will get `Array`. An Array is an object of type *Array*.
41+
An Array is an object of type *Array*.
4142

4243
Instead of using `[]` you can also use the the longer way and call the `[]` method
4344
of the *Array* class:
@@ -46,33 +47,33 @@ of the *Array* class:
4647

4748
## Creating an Array with #new
4849

49-
Besides using `[]`, you can create an Array by instanciating an Array with the `new` method.
50-
The `new` method accepts 2 optional parameters: The number of elements, and the element itself.
50+
Besides using `[]`, you can create an Array by instantiating an Array with the `new` method.
51+
The `new` method accepts two optional parameters: The number of elements, and the element itself.
5152

5253
If you call `new` without any parameter it will create an empty Array:
5354

54-
` Array.new` * # => []*
55+
` Array.new` *# => []*
5556

5657
If you only define the first parameter as an Integer, it will use this Integer to define
5758
the length of the new Array and will assign *nil* for each element:
5859

59-
` Array.new(2)` * # => [nil, nil]
60+
` Array.new(2)` *# => [nil, nil]*
6061

6162
If you pass an Array as first parameter it will return the defined Array:
6263

63-
` Array.new([1, 2, 3])` * # => [1, 2, 3]*
64+
` Array.new([1, 2, 3])` *# => [1, 2, 3]*
6465

6566
The actual interesting case is, if you pass both parameters.
6667
It will create an array of the length given in the first parameter, with each element
6768
being the second parameter. Here is an example:
6869

69-
` Array.new(3, 4.5)` * # => [4.5, 4.5, 4.5]*
70-
` Array.new(2, ['a', 'b'])` * # => [['a', 'b'], ['a', 'b']]
70+
` Array.new(3, 4.5)` *# => [4.5, 4.5, 4.5]*
71+
` Array.new(2, ['a', 'b'])` *# => [['a', 'b'], ['a', 'b']]*
7172

7273

73-
Another way of creating an Array is calling `Array()` with 1 parameter:
74+
Another way of creating an Array is calling `Array()` with a single parameter:
7475

75-
` Array('banana')` * # => ["banana"]*
76+
` Array('banana')` *# => ["banana"]*
7677

7778
This will create a new Array with only the given value and is the same as calling `['banana']`.
7879

4_Arrays/2_Accessing_elements/task.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,69 @@
33
---
44

55
*You will learn:*
6-
- how to get single elements from an Array
6+
- how to get a certain element from an Array
77
- how to get subsets of elements from an Array
88

99
---
1010

1111
Each element in an Array is associated with a fixed place – its *index*.
12-
The index is an Integer which allows to access an element in the Array.
12+
The index is an Integer by which you can access an element in the Array.
1313

1414
The index 0 points to the first element, the index 1 to the second element, etc.
1515
Negative indexes point to elements backwards from the last element. E.g. -1 points
1616
to the last element, -2 points to the second last element, and so on.
1717

18-
## Getting a single element from an Array
18+
## Getting an element from an Array
1919

20-
You can get the object from an Array at an index by using squared brackets:
20+
You can get the object from an Array at a certain index by using squared brackets:
2121

2222
` numbers = [2, 4, 9]` *# defining an Array `numbers`*
23-
` numbers[0]` *# => 2
24-
` numbers[1]` *# => 4
25-
` numbers[2]` *# => 9
26-
` numbers[-1]` *# => 9
23+
` numbers[0]` *# => 2*
24+
` numbers[1]` *# => 4*
25+
` numbers[2]` *# => 9*
26+
` numbers[-1]` *# => 9*
2727

2828
If there is no element present for the given index you will get a *nil* value:
2929

30-
` numbers[3]` *# => nil
30+
` numbers[3]` *# => nil*
3131

3232
`[]` is just an ordinary method that is defined for an instance of Array.
3333

3434
Another way for getting a single element is using the alias method `at`:
3535

36-
` numbers.at(0)` *# => 2
37-
` numbers.at(-1)` *# => 9
38-
` numbers.at(3)` *# => nil
36+
` numbers.at(0)` *# => 2*
37+
` numbers.at(-1)` *# => 9*
38+
` numbers.at(3)` *# => nil*
3939

4040
There are two methods for getting special elements of an Array: `first` and `last`.
41-
`first` – as you might have guessed – returns the first element (at index 0),
42-
and `last` returns the last element (at index -1):
41+
The method `first` – as you might have guessed – returns the first element
42+
(at index 0), and `last` returns the last element (at index -1):
4343

4444
` numbers.first` *# => 2*
4545
` numbers.last` *# => 9*
4646

4747
## Getting a subset of elements from an Array
4848

49-
You can also pass 2 parameters to the `[]` method. This allows to select a subarray
49+
You can also pass two parameters to the `[]` method. This allows to select a subarray
5050
by defining the index to start at and the number of elements you want to grab, e.g.:
5151

52-
` numbers[1, 2]` * # => [4, 9]*
52+
` numbers[1, 2]` *# => [4, 9]*
5353

54-
returns 2 elements starting at index 1. If there are no elements for the given indexes
54+
returns two elements starting at index 1. If there are no elements for the given indexes
5555
available, it returns *nil*:
5656

57-
` numbers[10, 2]` * # => nil*
57+
` numbers[10, 2]` *# => nil*
5858

5959
Another way to select a subarray from an Array is to pass a *Range* of the wanted
6060
indexes to `[]`:
6161

62-
` numbers[1..2]` * # => [4, 9]
62+
` numbers[1..2]` *# => [4, 9]*
6363

6464
In case the elements are not available for the indexes it will again return *nil*:
6565

66-
` numbers[5..10]` * # => nil*
66+
` numbers[5..10]` *# => nil*
6767

68-
For further information about the `[]` method, see (ruby-doc core: Array#[]).
68+
For more information about the `[]` method, see (ruby-doc core: Array#[]).
6969

7070
---
7171

@@ -76,6 +76,6 @@ Define a variable *first* and assign the first programming language to it.
7676

7777
Define a variable *last* and assign the last programming language to it.
7878

79-
Store the middle 3 programming languages in a variable *some_languages*.
79+
Store the three middle programming languages in a variable *some_languages*.
8080

8181
---

4_Arrays/3_Adding_elements/solution_spec.rb

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,30 @@
1212
end
1313

1414
if local_variables.include?(VARIABLE)
15-
it 'defines a variables "baggage" that has all the items' do
16-
expect(eval(VARIABLE.to_s)).to eq ITEMS
15+
before(:all) do
16+
@statements = CodeBreaker.parse( %q{ [['solution::code']] })
1717
end
1818

19-
if eval(VARIABLE.to_s) == ITEMS
20-
before(:all) do
21-
@statements = CodeBreaker.parse( %q{ [['solution::code']] })
22-
end
19+
it 'uses the unshift method to add "glasses"' do
20+
unshift = [{ lvar: VARIABLE }, :unshift, String]
21+
expect(@statements.include?(unshift)).to be true
22+
end
2323

24-
it 'uses the unshift method to add "glasses"' do
25-
unshift = [{ lvar: VARIABLE }, :unshift, String]
26-
expect(@statements.include?(unshift)).to be true
27-
end
24+
it 'uses the push or << method to add "shoes"' do
25+
push = [{ lvar: VARIABLE }, :push, String]
26+
arrows = [{ lvar: VARIABLE }, :<<, String]
2827

29-
it 'uses the push or << method to add "shoes"' do
30-
push = [{ lvar: VARIABLE }, :push, String]
31-
arrows = [{ lvar: VARIABLE }, :<<, String]
28+
includes_code = @statements.include?(push) || @statements.include?(arrows)
29+
expect(includes_code).to be true
30+
end
3231

33-
includes_code = @statements.include?(push) || @statements.include?(arrows)
34-
expect(includes_code).to be true
35-
end
32+
it 'uses the insert method to add "trousers" and "socks"' do
33+
insert = [{ lvar: VARIABLE }, :insert, Fixnum, String, String]
34+
expect(@statements.include?(insert)).to be true
35+
end
3636

37-
it 'uses the insert method to add "trousers" and "socks"' do
38-
insert = [{ lvar: VARIABLE }, :insert, Fixnum, String, String]
39-
expect(@statements.include?(insert)).to be true
40-
end
37+
it 'changes your baggage to contain "glasses", "shirt", "trousers", "socks", & "shoes"' do
38+
expect(eval(VARIABLE.to_s)).to eq ITEMS
4139
end
4240
end
4341
end

4_Arrays/3_Adding_elements/task.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ This unit will look into different ways of adding elements to an Array.
1616

1717
## Adding elements to the end of an Array
1818

19-
An Array instance has several methods for adding elements.
19+
An Array object has several methods for adding elements.
2020
If you want to add a *single* element to the end you can use the `<<` method:
2121

2222
` numbers = [1, 2, 3]`
2323
` numbers << 4` *# => [1, 2, 3, 4]*
2424

2525
You could also write `numbers.<<(4)`, so the missing *.* and *()* are just a bit of
26-
syntactical sugar.
26+
syntactic sugar.
2727

2828
A similiar method for adding an element to the end of an Array is `push`:
2929

@@ -35,13 +35,14 @@ many elements as you want in a single call:
3535

3636
` chars.push('d', 'e', 'f')` *# => ['a', 'b', 'c', 'd', 'e', 'f']*
3737

38-
Both `<<` and `push` will modify the given Array directly. If you check the values
39-
of the variables above after calling the methods on them they will contain the added values:
38+
Both `<<` and `push` will modify the given Array directly. If you check the values of
39+
the variables above after calling the `<<` or `push` methods they will contain the
40+
added values:
4041

4142
` numbers` *# => [1, 2, 3, 4] *
4243
` chars` *# => ['a', 'b', 'c', 'd', 'e', 'f']*
4344

44-
If you want to build a new Array out of an existing one by adding elements, the `+` method
45+
If you want to build a new Array from an existing one by adding elements, the `+` method
4546
will help you to combine two Arrays:
4647

4748
` numbers = [1, 2]`
@@ -56,7 +57,7 @@ The original Array will stay the same:
5657
## Adding elements to the beginning of an Array
5758

5859
If you want to add elements to the beginning of an Array instead, you can use the
59-
`unshift` method which takes 1 or more elements to add as arguments:
60+
`unshift` method which takes one or more elements to add as arguments:
6061

6162
` numbers = [1, 2]`
6263
` numbers.unshift(0)` *# => [0, 1, 2]*
@@ -81,7 +82,7 @@ all the values now:
8182

8283
` vegetables` *# => ['potato', 'cucumber', 'cauliflower', 'pepper']
8384

84-
Now that you have learned a couple of possibilities for adding elements to an Array
85+
Now that you have learned various methods for adding elements to an Array,
8586
let’s summarize them again:
8687

8788
` <<` *adds element at end modifies the original Array*

0 commit comments

Comments
 (0)