Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrewckinstler/e0ef6f72206a595e20c78b5cabb795c1 to your computer and use it in GitHub Desktop.
Save andrewckinstler/e0ef6f72206a595e20c78b5cabb795c1 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: The drop method takes the number that you pass into the function, say drop(2), and creates a new array with those removed from the front. If my array was musicalInstruments = ["guitar", "bass", "violin", "snare drum", "triangle"] and I wanted to get rid of the first three I would use drop(3) and it would return a new string of ["snare drum", "triangle"], while keeping the original array intact.

  • What did you Google to help you with this task, and how did you pick your results? I started with ruby drop array method and was mostly finding people using the delete function. So I changed my search to ruby array "drop" and found some better explainations there. I chose my results by looking at the code and seeing the ones that I was able to understand.

  • 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 string split method passes a string through the function .split and splits your string into an array filled with substrings based on the parameters you pass into the function. if I entered "I love movies".split it would give me the array ["I", "love", "movies"].

  • What did you Google to help you with this task, and how did you pick your results? THe link provided gave really good examples and I got most of my information from there but I had to google things like "regex" and I did a search for Ruby split string explain.

  • In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer: In JavaScript the slice() function takes an array and creates a new array based on the parameters you choose. In the parameters of the .slice function you can choose a begin and end point, starting at 0 and stopping, without removing, the second number you pass in.

If I have an array of [1, 2, 3, 4, 5, 6,] named array and use let newArray=array.slice(0,3); the newArray is going to be [1, 2, 3].

  • What did you Google to help you with this task, and how did you pick your results? I googled Javascript slice and found a few blogs. I chose my results by comparing what the blogs were saying to the MDN documentation. I found the information on the blogs simpler to wrap my head around but was able to see that it was the same information MDN was giving but more condensed.

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: Clue

  • 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: Instructions, player names
  2. Integer and/or float data: The number of cards in a players hand, the possible dice combinations
  3. Boolean data: whether it's a player's turn or not, whether the guess made to win the game is true or false, is the player guessing in the correct room to make the guess they want to make?
  4. Array data: Character names ["Col. Mustard", "Rev. Green", "Mrs. Peacock", "Prof. Plum", "Ms. Scarlett", "Mrs. White"] Weapons ["Candlestick", "revolver", "rope", "wrench", "dagger", "pipe"]
  5. Hash or Object data: ["player1":cards in hand] ["player2":current location]

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.

  • Folding laundry. Take one piece off laundry, fold, put away, repeat until all laundry is folded.

  • Taking a walk. Move forward with right foot, move forward with left foot, repeat until destination is reached.

  • Swimming laps. Swim to one end, return to starting point, repeat until desired amount of laps have been satisfied.

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

  • Calculating the total of a shopper's bill. Go through each item that has been scanned, add price, repeat until final total has been reached.

  • In an alarm clock app. If I set my alarm for 8:00 am the app would go through each minute until the condition for 8:00am was true at which point it would return a true statement and satisfy the iteration loop.

  • In a regristration form, if would go through each line to make sure that all information entered satisfies the condition required, i.e. date formats, email address formats, and if all conditions are met it would allow the user to proceed, but otherwise it would ask the user to reenter incorrect information.

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 there are braces instead of parenth around student on the second line.
.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 "sans-serif" is missing the hyphen on the fourth line.
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 max is replaced with min at the beginning of the second line.
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" instead of "a===b" on the first line.
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 "initialize" is spelled wrong on the third line.

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 Jul 24, 2019

@andrewckinstler overall nice work on this.

Remember with iteration to always start with a collection, and to perform an operation for each item in that collection. This will help you with describing iteration in a programming context.

I'd encourage you to check your syntax for all of the data types in the data types portion.

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