Turing Prep Chapter 4: Arrays, Hashes, and Nested Collections
Index of this series:
- Turing Prep Chapter 1: Make Mod 1 Easier Than It Otherwise Would Be
- Turing Prep Chapter 2: Your first passing tests!
- Turing Prep Chapter 3: Video walk-through of a few of the mythical creatures, like
- Turing Prep Chapter 4: Arrays, Hashes, and Nested Collections (This is what you’re reading right now)
- Turing Prep appendix: Troubleshooting Errors
You totally don’t have to look through the screencasts in order. I just wanted to call out array/hash manipulation on its own page.
Array Manipulation Exercises
These are from
I’ll add more screencasts for the other files in this directory soon:
> tree collections collections ├── README.md ├── advanced_nested_collections │ ├── nesting.rb // done │ └── nesting_test.rb // done ├── arrays.rb // done, what you're reading right now ├── hashes.rb // coming soon └── nested_collections.rb // coming soon
As I’ve mentioned before, I would recommend you try to stay ahead of me in this video. If you get stuck on making a test pass for more than a few minutes, check that spot of the video, then carry on.
This video is so long because I go into excruciating detail on each test, not just showing the given method that works, but showing how I would google for the right answers if I didn’t know them.
Googling is a skill. Get good at it. :)
Here’s an index of timestamps/what’s covered at that location for this Array manipulation video.
- 1:10 - How to use this video
- 2:05 - test_0
- 2:28 - test_1
- 3:05 - test_2
- 3:35 - using “pry” for the first time in this file
- 4:53 - test_22
- 8:33 - test_3
- 9:20 - Anki flashcard post I mention
- 10:12 - test_4
- 14:10 - test_a
- 15:18 - test_5
- 18:17 - test_b
- 18:36 - test_c
- 19:08 - test_6
- 21:33 - test_7
- 23:02 - test_8
- 27:04 - test_9
- 30:19 - test_10
- 30:59 - test_11
- 31:41 - why read the docs?
- 32:37 - test_12
- 34:58 - test_13
- 36:05 - test_14
- 38:10 - suggested next steps
- 38:46 - write down Array methods in a notebook.
Advanced Nested Collections
collections directory, there’s another directory,
advanced_nested_collections; this is well worth your time to play around with.
Here’s a walk-through:
I cover a lot of things in the video; here’s the index:
- 0:04 - The “tree” command: https://github.com/MrRaindrop/tree-cli
- 0:14 -
cdto the target file
- 1:10 - the importance of process over specific answers
- 1:54 - I probably won’t be coming up with the “best” solutions, and that’s OK
- 2:50 - Copying relative and absolute file paths to the clipboard
- 3:15 - run all tests, all skipped
- 3:23 - def test_list_of_olive_garden_employees
- 3:33 - exploring the
storesobject in Pry
- 4:29 - Start with other hash exercises; if you’ve not done any, this isn’t a good starting point.
- 4:50 - test_pancake_ingredients
- 5:42 - using .keys
- 6:30 - dealing with array of hashes
- 7:26 - test_rissotto_price
- 8:33 - test_big_mac_ingredients
- 9:52 - using .find; I used it wrong. Better usage examples: https://www.youtube.com/watch?v=2tTMAPT7rcw, https://apidock.com/ruby/Enumerable/find. Sorry.
- 10:40 - I’m still using it wrong. super sorry.
- 11:10 - Find is an Enumerable method, not Array method, which is why I had to look in a different spot in the docs
- 12:39 - test_list_of_restaurants
- 13:39 - test_list_of_dishes_names_for_olive_garden
- 14:20 - using .map for first time.
- 15:30 - convert .map to .each, per instructions
- 15:45 - using
continuein pry to move to next item in list
- 16:20 - difference between .each and .map
- 18:43 - test_list_of_employees_across_all_restaurants
- 21:13 - using ruby docs to get unstuck
- 22:10 - using .each with TWO arguments in block instead of one.
- 23:44 use .concat to avoid nested arrays
- 25:29 test_list_of_all_ingredients_across_all_restaurants
- 32:29 test_full_menu_price_for_olive_garden
- 37:13 test passes. Lets refactor, giving .reduce a shot! 😱
- 41:14 test_full_menu_for_olive_garden
- 48:38 I accidentally broke the prior test; fixing it
- 50:02 test_full_menu_price_for_olive_garden
- 53:51 it works! refactoring to use .reduce
- 1:03:00 explaining a gotcha with .reduce