Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save agallant121/81c025845a9d17a19ecdc0d201b1b3fd to your computer and use it in GitHub Desktop.

Select an option

Save agallant121/81c025845a9d17a19ecdc0d201b1b3fd 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 Ruby array [drop] method will drop the number of elements, based on the number put in with the [drop] command for the array, whose result will be an array with the elements that came after the number of dropped elements. Ex: testArray = [2, 4, 6, 8] testArray.drop(1) would result and arrsay with [4, 6, 8] since we only asked to drop 1 element which in this case was the number 2. If we switched the drop to testArray.drop(2) we should get [6, 8]

  • What did you Google to help you with this task, and how did you pick your results? I googled the exact drop array command from the link provided and actually went to the same website through my google search. There was a little confusion in their example because they used drop.(3) for the array [1, 2, 3, 4, 5, 6] with the result being [4, 5, 6] which could have either meant it will drop the first 3 of the array or drop all numbers up to and including 3. I then practiced it in my terminal to make sure that what I thought was correct was indeed, correct.

  • In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer: Ruby string breaks down an entire string of an array into sub-strings (I guess you could call them that) based on what you use as a delimiter. "What is love".split #=> ["What", "is", "love"]

  • What did you Google to help you with this task, and how did you pick your results? To find this I followed the link provided but then googled "What does the ruby string method do?", which led me to a stack overflow page, that in my opinion, had a more clear explanation of what it was.

  • In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer: When using slice, you are basicallly breaking up your original array into new, more precise arrays, without ruining the original. If one number is put after the slice command then it will "slice" out up to that number. If two numbers are put in, it will slice out through the first number or element and then show from the sliced out section to the remaining element listed. a = ["cow", "monkey", "goat", "lion"] a.slice(1); should return ["monkey", "goat", "lion"] If you did a.slice(1, 2); it should return ["goat", "lion"]

  • What did you Google to help you with this task, and how did you pick your results? I read the results from the first link and felt like I kind of understood it so I googled "slice array JavaScript":stackoverflow.com to show me only results from that website.

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: Chance card entries, Property names, Community Chest entries.
  2. Integer and/or float data: Various dollar amounts available, Pass go and collect $200, number of houses and hotels owned.
  3. Boolean data: Yes/No when offered money for a property, Chance card will/won't send you directly to jail. Yes/no on whether you choose to buy properties you land on.
  4. Array data: Lists of property owned, Various bill denominations, all possible chance/community chest card entries.
  5. Hash or Object data: The key value pairs here are going to be the values of the properties. Each propert will have a money value attached to it. Passing go and collecting $200 will also be hash data for Monopoly.

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.

  • Putting on socks--socks--sock--take one sock/open sock on ankle end/pull open end around toes/pull up until foot is covered--repeat with next sock on opposite foot. It is an iteration because it is a daily activity that needs to be broken down into steps in order to complete the action.

  • Unloading dishwasher--dishes--dish--remove dish and place it back in its assigned spot--repeat with all dishes until dishwasher is empy placing dishes in their assigned spots. It is an interation because it does not randomly happen, there are assigned movements and order that needs to be followed to successfully unload a dishwasher.

  • Vacuuming a room--vacuum strokes--vacuum stroke--move vacuum forward and then move it backward covering previously un-vacuumed area--Repeat this until entire room has been covered by the vacuum. This is an iteration because an action needs to be repeated to get the desired result of cleaning the floor of a room with a vacuum.

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

  • Find average ages of different age groups--age groups--age group--use assigned age groups and average out the integers representing ages for the age group to get an average age for that group--repeat this process until you have an average age of all age groupings.

  • Find sums of salaries per department--salaries--salary--take specific department's salaries and add them together one salary at a time until you have a sum representing the department's total salary expenditure--repeat until there is a sum for each department.

  • Keep track of programmers working on same project--programmers--programmer--boolean data can be tracked of whether they did or did not log in to edit a certain program. If marked that they did log in then add that log in to a total--repeat with every programmer who logs in to work on a specific project.

4. Identifying Mistakes (15 min)

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

Parentheses instead of braces. Hyphen at the end is missing. Switched the word “max” with “min”. a == b became b == b “Initialized” was mispelled.
Original Mistakes Problem
students.each do |student|
  puts "Welcome, #{student}"
end
students.each do |student|
  puts "Welcome, #(student)"
end
The problem is...
.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...
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...
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...
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...

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. The last part about updating the bash profile was super easy to follow, however, when I did it I did not get the same new terminal window that she did in the video after I follwed her instructions. I would just like to know if there are common errors that occur and how one might address those errors to be able to self correct.
@damwhit
Copy link

damwhit commented Jul 24, 2019

@agallant I think we addressed the above question after Monday's session - let me know if you want further follow up

@damwhit
Copy link

damwhit commented Jul 24, 2019

Also, see if you're able to get your answers in the far right boxes for the identifying mistakes portion

@agallant121
Copy link
Author

agallant121 commented Jul 24, 2019 via email

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