Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save monstaro/3ebfc48c1a16e27f1c98f122c374d2a5 to your computer and use it in GitHub Desktop.

Select an option

Save monstaro/3ebfc48c1a16e27f1c98f122c374d2a5 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: If an array spanned from 0-6, the drop method will select all numbers after the specified number (n), so in your array of 0-6, and a drop 3, the array would return 3, 4, 5 & 6.

  • What did you Google to help you with this task, and how did you pick your results? I Googled "drop array" ruby and filtered the results to pages published since Jan 2018. I eventually found a page on freecodecamp.com which helped give me context with other examples of arrays, then the description of the drop array made more sense to me.

  • In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer: The split in Ruby will split up a string into separate strings. There are numerous different ways you can split up a string. For example, if you have a string of Cody Smith you can split up a string to return in various ways, such as every seperate letter, every seperate letter with the excpetion of some of the first or last letters, to return a string with the exception of certain specified characters, the list goes on.

  • What did you Google to help you with this task, and how did you pick your results? I did a similar method as listed above, Googling "split string ruby" and limiting my results to sites posted since Jan 2018. I read a few other sites to help give me a clearer context of splits, strings, how they connect, and what they can do. Ultimately the clearest explanation and example waws on the ruby-doc page, but I read about splits on ThoughtCo and DigitalOcean as well to understand through different examples.

  • In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer: Slice will return selections from a list of variables based on the selections you have made. For example, if your list of variables was different types of pie (Apple, Grape, Key Lime, Chocolate, Banana Cream) you could slice it into two different categories, Jelly and Custard. If you want to return just Jelly pies and not Custard-y pies, you could split 0, 2. This will include variables 0 and 1. In these splits, the first variable is included but the variable corresponding to the higher number is not included. You could then also include a split for Custard pies, simply with the number 2. This will include all variables from number 2 to the end. In the end you have Apple and Grape split into the Jelly category and Key Lime, Chocolate, & Banana Cream all in the custard category.

  • What did you Google to help you with this task, and how did you pick your results? Same methods as above, I googled "javascript array slice" and filtered results since Jan 2018. I found a few results but the most useful was on ZenDev. The rest of the sites had a lot of ads. The link included in this lesson was also useful.

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 (I don't remember the rules of many board games...some of these examples may not be how the game is played but hopefully it gets the point accross)

  • 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: Game name, instructions
  2. Integer and/or float data: Spaces available to play, space where each player is, how many spaces until finish, how many spaces ahead/behind a player is.
  3. Boolean data: If a player rolls a 2 and a 5, then move seven spaces. If a player has a get out of jail free cards and uses the get out of jail free card, the player will get out of jail and keep moving through the board.
  4. Array data: Card deck, dice.
  5. Hash or Object data: {120 Dollars-Can buy house, car. 180 Dollars-Can buy bank, school.} {Land on Space 12, 24-Go to Jail}

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.

  • Factory workers (assembly line) People who work in an assembly line repeat the same action repeatedly until the end of their shift. An exampe would be: Scenario-Assembly Line. Collection-Toy. For each-toy. Do this-screw piece A to piece B. Then-repeat with next toy until 5:00.

  • Subway Employees. Repeat the same action in different ways. Scenario: Sandwich maker. Collection: Sandwich. For each: Sandwich. Do this: Add X, X, & X. Then: repeat until 5:00

  • Scenario: Lifting weights. Collection: Reps. For each: Rep. Do this: Lift weight, lower weight. Then: Repeat 10 times.

  • 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.

  • Start each new sentence with a capital letter. Scenario: Capitalizing the first letter of each sentence. Collection: '.' For each: '.' Do this: Capitalize the first letter.

  • Scenario: Scan profiles for people 25 years old. Collection: Profiles. For each: Profile. Do this: 1. Scan for age. 2. If age is 25, push advertisement X to them.

  • Scenario: Check e-mail server for new e-mails. Collection: Minutes. For each: Minute. Do this: Scan e-mail server for this inbox.

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... parenthesis around 'student'
.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...there is no dash in between 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...both sides include a min(score) but one side needs a max(score) to compliment the min(score)
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... b==b. I'm not sure what this code means but if it's supposed to reject b==b, that wouldn't make sense because b should equal b.
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 word 'intialize'

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:

  1. This assignment was very helpful in reinforcing the information we discussed in the last zoom meeting. It was helpful because I had time to really sink and think into some of these concepts beyond the surface level understanding I had. It's nice to have the introduction in the zoom meetings and then to have the time to really explore on the assignments.
@damwhit
Copy link

damwhit commented Jul 24, 2019

@monstaro glad that you found these useful! Most of the learning you do at Turing will be on your own working through projects and assignments so you have a lot more to look forward to 😃

@damwhit
Copy link

damwhit commented Jul 24, 2019

I'd encourage you to come up with some more example values for the data types portion as it is super valuable to practice the syntax of typing them out.

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