Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 23 additions & 26 deletions enumerables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,46 @@ def spicy_foods
]
end

# given an array of spicy foods, **return an array of strings**
# with the names of each spicy food
def get_names(spicy_foods)
# your code here
spicy_foods.map do |food|
food[:name]
end
end

# given an array of spicy foods, **return an array of hashes**
# where the heat level of the food is greater than 5
def spiciest_foods(spicy_foods)
# your code here
spicy_foods.filter do |food|
food[:heat_level] > 5
end
end

# given an array of spicy foods, **output to the terminal**
# each spicy food in the following format:
# Buffalo Wings (American) | Heat Level: 🌶🌶🌶
# HINT: you can use * with a string to produce the correct number of 🌶 emoji.
# "hello" * 3 == "hellohellohello"
def print_spicy_foods(spicy_foods)
# your code here
spicy_foods.each do |food|
puts "#{food[:name]} (#{food[:cuisine]}) | Heat Level: " + "🌶" * food[:heat_level]
end
end

# given an array of spicy foods and a string representing a cuisine, **return a single hash**
# for the spicy food whose cuisine matches the cuisine being passed to the method
def get_spicy_food_by_cuisine(spicy_foods, cuisine)
# your code here
spicy_foods.find do |food|
cuisine == (food[:cuisine])
end
end

# Given an array of spicy foods, **return an array of hashes**
# sorted by heat level from lowest to highest
def sort_by_heat(spicy_foods)
# your code here
spicy_foods.sort do |lowest, highest|
lowest[:heat_level] - highest[:heat_level]
end
end

# given an array of spicy foods, output to the terminal ONLY
# the spicy foods that have a heat level greater than 5, in the following format:
# Buffalo Wings (American) | Heat Level: 🌶🌶🌶
# HINT: Try to use methods you've already written to solve this!
def print_spiciest_foods(spicy_foods)
# your code here
spicy_foods.each do |display|
if display[:heat_level] > 5
puts "#{display[:name]} (#{display[:cuisine]}) | Heat Level: " + "🌶" * display[:heat_level]
end
end
Comment on lines +43 to +47

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch you spacing and naming. If you have good spacing, it make it easier to follow your code which can help with debugging and reading.

Suggested change
spicy_foods.each do |display|
if display[:heat_level] > 5
puts "#{display[:name]} (#{display[:cuisine]}) | Heat Level: " + "🌶" * display[:heat_level]
end
end
spicy_foods.each do |food|
if food[:heat_level] > 5
puts "#{food[:name]} (#{food[:cuisine]}) | Heat Level: " + "🌶" * food[:heat_level]
end
end

end

# given an array of spicy foods, return an integer representing
# the average heat level of all the spicy foods in the array
def average_heat_level(spicy_foods)
# your code here
average_heat = spicy_foods.sum do |food| food[:heat_level]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, naming is important.

Suggested change
average_heat = spicy_foods.sum do |food| food[:heat_level]
total_heat = spicy_foods.sum do |food| food[:heat_level]

end
average_heat / spicy_foods.length
end