-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivity.rb
More file actions
82 lines (62 loc) · 1.68 KB
/
activity.rb
File metadata and controls
82 lines (62 loc) · 1.68 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
76
77
78
79
80
# arr = [1,3,5,7,9,11]
# number = 3
# def does_appear(array,number)
# array.include?(number)
# end
# puts does_appear(arr, number)
#----------------------------------------------------------------
# number = ""
# #check if user input is a negative number or 0
# while number.to_i.positive? == false
# puts "Please enter a number between 0 and 100"
# number = gets.chomp().to_i
# end
# if number > 0 && number < 50
# puts "#{number} is between 0 and 50"
# elsif number > 51 && number < 100
# puts "#{number} is between 51 and 100"
# elsif number > 100
# puts "#{number} is above 100"
# else
# puts "#{number} does not satisfy any condition"
# end
#----------------------------------------------------------------
# keyword = "STOP"
# input = ""
# while input != keyword
# puts "Enter anything to get a random number - otherwise STOP"
# input = gets.chomp()
# if input == keyword
# break
# end
# puts rand(0...100)
# end
#----------------------------------------------------------------
arr = [6,3,1,8,4,2,10,65,102]
def is_divisible (array)
new_array = array.select(&:even?)
puts new_array.join(" ")
end
is_divisible(arr)
# def is_divisible (array)
# array.select { |number| number.even?}
# end
# puts is_divisible(arr)
# def is_divisible (array)
# divisible_by_two = Array.new
# array.map do |number|
# if number % 2 == 0
# divisible_by_two.push(number)
# end
# end
# puts divisible_by_two.join(" ")
# end
# is_divisible(arr)
# arr = [6,3,1,8,4,2,10,65,102]
# new_arr = []
# arr.map do |number|
# if number % 2 == 0
# new_arr.push(number)
# end
# end
# puts new_arr.join(" ")