Skip to content

Instantly share code, notes, and snippets.

@b0uma
Last active September 8, 2015 17:52
Show Gist options
  • Save b0uma/275ba16b156a074fbcfe to your computer and use it in GitHub Desktop.
Save b0uma/275ba16b156a074fbcfe to your computer and use it in GitHub Desktop.

Week 1: Tuesday prep for Wednesday morning

  • Please go through the preread content carefully before Wednesday's class at 9 AM. Watch, read, and practice with cohort-mates!
  • Content marked (optional) is for review or extra learning.
  • Read about the flipped classroom philosophy here (optional): https://en.wikipedia.org/wiki/Flipped_classroom
  • There's a lot of material here, so budget time appropriately today. Think of this as another challenge.

Learning Goals

  1. Review iteration conceptually
  2. Apply iteration to linear search
  3. Learn and practice recursion syntax and recursive algorithms
  4. Practice iteration and looping syntax in Ruby
  5. Learn the important methods in the Enumerable Module with a focus on Arrays and Hashes

Preread Content

(4 videos, 1 blog post, 1 documentation page)

PART 1

These videos target the C programming language, which you are not expected to know. Don't get hung up on the syntax and instead focus on the concepts. These cover learning goals 1-3. Come to class with questions!


PART 2

Practice the code snippets from the following post in your terminal using the irb command in iTerm. Here are the loops in the order they appear; feel free to skip optional ones. You don't need to read every word of this blog post, just cover the keywords listed below and practice in irb. This covers learning goal 4.

  • loop, break, next, redo (the info in the article for retry is wrong, do not read)
  • while and until
  • while and until using begin syntax
  • for
  • each
  • skip each_index, that method has been removed from Ruby as of 2.2 and possibly before)
  • times (optional, not really used)
  • upto, step (optional, not really used)

PART 3

Below is the documentation page for the Enumerable module. Both Array and Hash implement the Enumerable methods. Each method name is prefixed with a pound sign as in Enumerable#first. This means first is an instance method and works on objects which are of classes that include the Enumerable module (classes like Array and Hash). arr = Array.new arr << 10 arr.first # this line returns 10

Look into the following methods as described in the link in the bottom of this section and type the code examples in irb. Remember that the # sign means that the method is an instance method. If there is a / such as #collect/#map, this means that the two methods #collect and #map are EXACTLY THE SAME.

  • Information: #count, #first, #include?, #none?, #max and #min, #max_by and #min_by
  • Transformation: #collect/#map, #detect/#find, #select, #inject/#reduce, #reject, #sort, #sort_by, #to_a, #to_h (only in Ruby 2.1+, don't freak out if it doesn't work), #group_by
  • Iteration: #each_with_index, #reverse_each

The documentation language is quite dry and difficult to understand. You will get the most from practicing the examples in irb. This covers learning goal 5.

[Enumerable module (30 minutes)] (http://ruby-doc.org/core-2.2.3/Enumerable.html)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment