-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcommands.txt
74 lines (52 loc) · 1.14 KB
/
commands.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
IRB exercises
Each Ruby command will return a value. Sometimes, these values are not what we expect.
Try the following Commands:
string = "Hello World"
=> fill_in_what_irb_returns_here
string.reverse
=> fill_in_what_irb_returns_here
string
=> fill_in_what_irb_returns_here
array = [3,1,2]
=> fill_in_what_irb_returns_here
array.sort
=> fill_in_what_irb_returns_here
array
=> fill_in_what_irb_returns_here
array.sort!
=> fill_in_what_irb_returns_here
array
=> fill_in_what_irb_returns_here
=> What do you think the exclamation mark indicates?
puts "Hello Ruby"
=> fill_in_what_irb_returns_here
array = [1,2,3,4]
=> fill_in_what_irb_returns_here
array.each do |e|
e**2
end
=> fill_in_what_irb_returns_here
array.each { |e| e**2 }
=> fill_in_what_irb_returns_here
array
=> fill_in_what_irb_returns_here
array.map do |e|
e**2
end
=> fill_in_what_irb_returns_here
array
=> fill_in_what_irb_returns_here
array = [1,2,3]
array.inject(0) do |sum, e|
sum += e
sum
end
=> fill_in_what_irb_returns_here
array
=> fill_in_what_irb_returns_here
array.reject do |e|
e > 2
end
=> fill_in_what_irb_returns_here
array
=> fill_in_what_irb_returns_here