-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Enumberable Lab #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Shantelgray
wants to merge
2
commits into
learn-co-curriculum:main
Choose a base branch
from
Shantelgray:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Enumberable Lab #16
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||
| 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] | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, naming is important.
Suggested change
|
||||||
| end | ||||||
| average_heat / spicy_foods.length | ||||||
| end | ||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.