-
Notifications
You must be signed in to change notification settings - Fork 0
/
e4.rb
25 lines (22 loc) · 1.03 KB
/
e4.rb
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
def func_any(hash)
# Check and return true if any key object within the hash is of the type Integer
# If not found, return false.
hash.any?{ |key, value| key.integer? }
end
def func_all(hash)
# Check and return true if all the values within the hash are Integers and are < 10
# If not all values satisfy this, return false.
hash.all?{ |key, value| value.integer? and value < 10 }
end
def func_none(hash)
# Check and return true if none of the values within the hash are nil
# If any value contains nil, return false.
hash.none?{ |key, value| value.nil? }
end
def func_find(hash)
# Check and return the first object that satisfies either of the following properties:
# 1. There is a [key, value] pair where the key and value are both Integers and the value is < 20
# 2. There is a [key, value] pair where the key and value are both Strings and the value starts with `a`.
hash.find{ |key, value| (( key.is_a? Integer and value.is_a? Integer and value < 20 ) or
( key.string? and value.string? and value[0] == 'a' )) }
end