-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathblocks-sam-rashad.rb
More file actions
75 lines (50 loc) · 1.49 KB
/
blocks-sam-rashad.rb
File metadata and controls
75 lines (50 loc) · 1.49 KB
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
75
# Write a loop that prints the numbers 1 to 20.
my_num = 1..20
my_num.each do |value|
puts value
end
# Write a loop that prints the numbers 1 to 20 using a different approach than previously used.
nums_array = Array(my_num)
p nums_array
#Write a loop that prints only even numbers from 20 to 0.
new_num = 0..20
new_num.each do |range|
if range.even?
p range
end
end
#Create a method that takes in an array of numbers and returns a new array with all the numbers multiplied by 5.
array = [0,1,2,3,4,5,6,7,8,9]
def times_five value
value.map do |value|
p value*5
end
end
times_five array
#Create a method that takes in an array of lowercase words and capitalizes all of the words, permanently modifying the original array.
array = ['car', 'boats', 'motorcycle']
def capital value
value.map do |value|
p value.capitalize
end
end
capital array
#Create a method that takes in an array of numbers and returns the largest number in the array.
array = [11,22,33,44,55,66,77,88,99]
def largest_number array
puts array.max
end
largest_number array
#Create a method that takes in an array of numbers and returns the smallest number in the array.
array = [11,22,33,44,55,66,77,88,99]
def smallest_number array
puts array.min
end
smallest_number array
#Create a method that takes in an array of numbers and returns only the odd numbers sorted from least to greatest.
new_num = 20..50
new_num.each do |range|
if range.odd?
p range.sort
end
end