Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ZoeKHarvey/84f311c4f688f3a083c3226a0f7614c8 to your computer and use it in GitHub Desktop.
Save ZoeKHarvey/84f311c4f688f3a083c3226a0f7614c8 to your computer and use it in GitHub Desktop.
Mod 0 Session 2 Practice Tasks

Session 2 Practice Tasks

The assignments listed here should take you approximately 2 hours.

To start this assignment, click the button in the upper right-hand corner that says Fork. This is now your copy of the document. Click the Edit button when you're ready to start adding your answers. To save your work, click the green button in the bottom right-hand corner. You can always come back and re-edit your gist.

1. Documentation and Googling (60 min)

Documentation of a langauge, framework, or tool is the information that describes its functionality. For this part of the practice tasks, you're going to practice digging into documentation and other reference material.

NOTE: The linked documentation for each question below is a good starting place, but you should also be practicing your Googling skills and sifting through the results to find relevant and helpful sites.

  • In your own words, what does the Ruby array drop method do? As you're explaining, be sure to provide an example. Your answer: It takes out the first elements in an array. So you have a list of inventory at a bar, and you need to weigh each bottle to keep track of how much liquor you sold. You weigh all of the Jack Daniels first, and then you can use the array drop method to process that you finished with that type of liquor, and immediately move it out of the array. I think, I'm not super sure about that example but that's what I interpreted from the definition.

  • What did you Google to help you with this task, and how did you pick your results? First I just googled what the Ruby array drop method was. I found definitions but they didn't make sense to me out of context. So then I watched a tutuorial on Ruby and worked on trying to figure out why you would need to do this to an array to begin with. I used rubycuts.com along with javatpoint to get the definitions, and then a few different tutorials on youtube to attempt to gain a bit more understanding on it.

  • In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer: I believe that it's used to split an array into different parts. If you had an array of dates in May (1st, 2nd, 3rd) and wanted to split them into separate days, you could use the string split method.

  • What did you Google to help you with this task, and how did you pick your results? Similiarly as the last question, I got a basic definition and then watched a tutorial on it, and went back and redifined some of the vocabularly that I wasn't familiar with, until I got an understanding of why you'd need split an string.

  • In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer: Similarly to the Ruby string method, the array slice method separates objects from arrays. With the the slice method, you can separate multiple parts of an array, to form another array. For example, you can have an array of months in a year, and form another array that runs from May to July (that would be month 5, 6, and 7).

  • What did you Google to help you with this task, and how did you pick your results? I looked at a lot of examples because it confused me how this was different from the split method.

2. Data Types (15 min)

Imagine that you're taking your favorite board game and turning it into a computer-based game.

  • Name of board game: Monopoly

  • Use the space below to categorize game data into each of the following data types. You should have a minimum of two pieces of data for each category.

  1. String data: Product name: "Monopoly", names of properties: "Railroad", etc., commands from each card drawn: "Go to Jail".
  2. Integer and/or float data: How much money each property costs to buy, how much your opponents owe you for landing on that owned property, how much money you are all left with at the end of the game.
  3. Boolean data: If it is true that a player owns the property that you just landed on, you must pay them. If it's false that someone owns the property, you have the option to buy the property or not. If it's true that you cross go, you collect money from the bank, if false, you do not.
  4. Array data: Names of players, names of all possible properties to own, names of properties each player owns.
  5. Hash or Object data: Not super confident with this one. I think an example of object data could be each card that represents the properties. The state of each card is the name, and the color (as they're color-coded), while the behavior could be its cost to buy, how much you can collect if another player lands on that property, and taxes owed if you buy it. Or perhaps the command cards, where the state of each card is the name/color, and the behavior would be what it makes you do (go to jail, pass GO).

3. Iteration (30 min)

  • Create a list below of three real-life situations where iteration is used. For each situation, explain why it would be an example of iteration.

  • Serving drinks at a bar: the repetition of serving customers is standard at its core: the bartender takes an order, pours/makes their drinks, takes the payment, and then repeats the task with the next customer until all customers are served (or their shift is over). It can almost be a slightly longer iteration if you take into account other standards of service including greeting the customer and thanking them.

  • Retail employees use iteration while folding their merchandise. They start with the first item, go through the steps of folding it, putting it in its proper place and then starting anew with the next item until they are all folded and put away.

  • Accounting for inventory uses iteration. You would first count all of one product, log how much you have in stock, and then start with the next product, until everything in stock is accounted for.

  • Create a list below of three programming situations where iteration would be used. For each situation, explain why it would be an example of iteration.

  • If you wanted to limit the times someone could enter an incorrect password at login, you could make it so the program would read the password, determine whether or not it was correct, and repeat the process 5 times until it locks the user out for a certain amount of time. Likewise, if the program has unlimited attempts allowed, you could alter the iteration so the program would determine whether or not it was correct, inform the user that that it was incorrect and to try again, until the correct password was entered and they gained access. Both of these would be iteration because it repeats a specific process until the endgame occurs (either too many failed attempts, or the correct password is given).

  • Many programs now have a program that alerts the user how much sleep they would get if they went to bed at different times. The user puts in the time when they need to wake up and their ideal amount of sleep each night, and their phone alerts them when they need to go to bed in order to get that amount of sleep. This could be an iteration (or at least for how I use the app) because my phone alerts me at the bedtime to get 9 hours of sleep, 7 hours, and then 5 hours each night. It stops alerting me when I let the phone know that I'm in bed. The program, I would assume, could have the time I want to wake up (8am) minus the amount of desired hours (9, 7, 5) to know when to alert me (11pm, 1am, 3am). This process continues each night until I either tell it to stop, or it reaches 5 hours of desired sleep.

  • For releases of popular concerts or clothing lines, etc., there are bots that people use to keep refreshing the page at lightning speed to that the moment the tickets/products go online, the bot can immediately buy the product before it sells out. I would imagine that it would just be some sort of iteration in the programming that would tell the bot to refresh the page every .10 seconds (or however fast), attempt to buy the product, and if it doesn't work yet, keep refreshing until it works.

4. Identifying Mistakes (15 min)

The following code examples each contain a mistake. Describe the problem for each.

Original Mistakes Problem
students.each do |student|
  puts "Welcome, #{student}"
end
students.each do |student|
  puts "Welcome, #(student)"
end
The problem is...The incorrect one uses parenthesis instead of braces for the iteration.
.main-content {
  font-size: 12px;
  border: 3px solid black;
  font-family: sans-serif;
}
.main-content {
  font-size: 12px;
  border: 3px solid black;
  font-family: sans serif;
}
The problem is...It doesn't use a hyphen between the words "sans" and "serif".
log(2, (1022 * ((score - min(score) over ()) / ((max(score) over ()) - (min(score) over ()))) + 2)::numeric) log(2, (1022 * ((score - min(score) over ()) / ((min(score) over ()) - (min(score) over ()))) + 2)::numeric) The problem is...There is no maximum in the second one, so it's telling the computer to negate the minimum value from the minimum value instead of from the maximum.
arr.product(arr).reject { |a,b| a == b }.any? { |a,b| a + b == n } arr.product(arr).reject { |a,b| b == b }.any? { |a,b| a + b == n } The problem is...The variables "a" and "b" are mixed up in the incorrect one.
class Cat
  attr_reader :color, :name
  def initialize(data)
    @name = data[:name]
    @color = data[:color]
  end
end
class Cat
  attr_reader :color, :name
  def intialize(data)
    @name = data[:name]
    @color = data[:color]
  end
end
The problem is...the second option spells "iteration" incorrectly.

5. Modify your Bash Profile (10 min)

  • Watch this video and follow each step to modify your own bash profile. As mentioned in the video, you will need this snippet below:
# get current branch in git repo
function parse_git_branch() {
  BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
  if [ ! "${BRANCH}" == "" ]
  then
    STAT=`parse_git_dirty`
    echo "[${BRANCH}${STAT}]"
  else
    echo ""
  fi
}

# get current status of git repo
function parse_git_dirty {
  status=`git status 2>&1 | tee`
  dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
  untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
  ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
  newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"`
  renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"`
  deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"`
  bits=''
  if [ "${renamed}" == "0" ]; then
    bits=">${bits}"
  fi
  if [ "${ahead}" == "0" ]; then
    bits="*${bits}"
  fi
  if [ "${newfile}" == "0" ]; then
    bits="+${bits}"
  fi
  if [ "${untracked}" == "0" ]; then
    bits="?${bits}"
  fi
  if [ "${deleted}" == "0" ]; then
    bits="x${bits}"
  fi
  if [ "${dirty}" == "0" ]; then
    bits="!${bits}"
  fi
  if [ ! "${bits}" == "" ]; then
    echo " ${bits}"
  else
    echo ""
  fi
}

export PS1="\u\w\`parse_git_branch\`$ "

5. Questions/Comments/Confusions

If you have any questions, comments, or confusions from the any of the readings that you would an instructor to address, list them below:

@damwhit
Copy link

damwhit commented May 29, 2019

Overall, nice work.

For the iteration situations, always start with a collection of something. For example, in Monopoly, you could have a collection of players. The iteration could be for each player, allow them a turn, then repeat for the next player in the collection.

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