File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 1+ def func_any ( hash )
2+ # Check and return true if any key object within the hash is of the type Integer
3+ # If not found, return false.
4+ hash . any? { |k , i | k . is_a? Integer }
5+ end
6+
7+ def func_all ( hash )
8+ # Check and return true if all the values within the hash are Integers and are < 10
9+ # If not all values satisfy this, return false.
10+ hash . all? { |k , v | v < 10 }
11+ end
12+
13+ def func_none ( hash )
14+ # Check and return true if none of the values within the hash are nil
15+ # If any value contains nil, return false.
16+ hash . none? { |k , v | v == nil }
17+ end
18+
19+ def func_find ( hash )
20+ # Check and return the first object that satisfies either of the following properties:
21+ # 1. There is a [key, value] pair where the key and value are both Integers and the value is < 20
22+ # 2. There is a [key, value] pair where the key and value are both Strings and the value starts with `a`.
23+ hash . find { |k , v |
24+ ( k . is_a? Integer and v . is_a? Integer and v < 20 ) or
25+ ( k . is_a? String and v . is_a? String and v [ 0 ] == 'a' ) }
26+ end
You can’t perform that action at this time.
0 commit comments