Skip to content

Conversation

@sjlee3157
Copy link

@sjlee3157 sjlee3157 commented Aug 7, 2018

Random Menu Generator

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
For the places where arrays were used, could using a hash work? Could it work easily? Why or why not? Yes, we could use 3 hashes instead of 3 arrays. However, an array works just as well here, because we are only working with two "keys", both of which arrays already use: 1) array value and 2) array index. A hash is unnecessarily complicated. What we could do instead is refactor the code using an array of hashes for the 3 linked arrays. But if we don't plan to scale up the number of properties each menu item has, that's also unnecessary.
Did you find repetitions of the same or similar code? Why did you have to do it that way? Yes. Lines 11-13 and lines 34-36 are one example. Writing more code to split all three arrays at once is much more trouble than its worth. Another example is line 19, where n = gets.chomp has to be repeated inside the while case loop.
Did you use any loops? If so, how did it help solve a problem? Yes. The while loop (lines 17-29) deals with a requirement that the user must satisfy before the program will continue. The each loop (lines 38-42) performs an action on the first level of three linked arrays and repeats the same action on each level.

@sjlee3157 sjlee3157 changed the title Create random-menu.rb Sammi-Jo's random-menu.rb (nodes) Aug 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant