-
-
Save RickArora/912c923c2f69302544185faae3614a2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write a method, adult_in_group?(people), that accepts an array containing people. | |
# The method should return true if there is at least 1 person with an age of 18 or greater. | |
# The method should return false otherwise. | |
def adult_in_group?(people) | |
people.each do |arr| | |
arr.each do |key, value| | |
if(arr["age"] >= 18) | |
return true | |
end | |
end | |
end | |
return false | |
end | |
people_1 = [ | |
{name: "Jack", age: 17}, | |
{name: "Jill", age: 21}, | |
{name: "Alice", age: 15}, | |
{name: "Bob", age: 16} | |
] | |
p adult_in_group?(people_1) # => true | |
people_2 = [ | |
{name: "Jane", age: 12}, | |
{name: "John", age: 13}, | |
{name: "Ashley", age: 10}, | |
{name: "Bill", age: 16} | |
] | |
p adult_in_group?(people_2) # => false | |
ERROR: | |
Rickys-MacBook-Pro:ricky_arora_advanced_methods_exercise Rtyer$ ruby 02_adult_in_group.rb | |
Traceback (most recent call last): | |
5: from 02_adult_in_group.rb:22:in `<main>' | |
4: from 02_adult_in_group.rb:6:in `adult_in_group?' | |
3: from 02_adult_in_group.rb:6:in `each' | |
2: from 02_adult_in_group.rb:7:in `block in adult_in_group?' | |
1: from 02_adult_in_group.rb:7:in `each' | |
02_adult_in_group.rb:8:in `block (2 levels) in adult_in_group?': undefined method `>=' for nil:NilClass (NoMethodError) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment