Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save cammac60/d70deac0a67e9ff09374c6b1f3239b3d to your computer and use it in GitHub Desktop.

Select an option

Save cammac60/d70deac0a67e9ff09374c6b1f3239b3d 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: This method will drop elements from an array based on the index number you provided (6 will drop the first 6 elements lowest on the index) and return the rest of the elements. Example: a = [1, 2, 3, 4, 5, 6] a.drop(4) #=> [5, 6]

  • What did you Google to help you with this task, and how did you pick your results?

Just searching the term brought up a lot of mixed results so I put quotations around "Ruby" and "drop". After this I was able to find a lot of sites with info on different methods of removing items from arrays in Ruby. Many of the sites covered a lot of different methods so once I opened each site I did a ctrl+f search for "drop" and was able to find results.

  • In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer: This is a method of splitting a string into an array of strings. There are multiple variations, some can split strings by each word and other can split them by each letter, and several other variations. Example: "Here we go".split #=> ["Here", "we", "go"]

  • What did you Google to help you with this task, and how did you pick your results? Because there are a lot of different methods on splitting strings this one was a bit harder to find specific results on. I used quotations again and eventually searched for: "Ruby" "split string" array and found some close results on Stack Overflow. I refinded my search further to: "Ruby" "split string" array:stackoverflow.com and the top result contained the exact question and answer I was looking for.

  • In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer: This is a method of cutting the beggining and/or end of an array and getting an output shallow array that contains the remaining elements. The first and second integer can be thought of as "from" and "until". Example: var cities= ["Tokyo", "Jakarta", "London", "Denver", "Cairo", "Paris"]; cities.slice(3, 5) #=> ["Denver", "Cairo"] In this example the 3 represents where the new array will start and 5 indicates which index the array will stop at.

  • What did you Google to help you with this task, and how did you pick your results? This search was a bit easier to find results for right off the bat. I did have to use quotations around "array slice" but I was able to find a few sites just using: Javascript "array slice"

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

  • 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: "doctor", "artist", "athlete"
  2. Integer and/or float data: 50000, 25000, 100000
  3. Boolean data: owns home? true/ retired? false
  4. Array data: familysize= [1, 2, 3, 4, 5, 6]
  5. Hash or Object data: { "Doctor": "Cameron", "Athlete": "Bob", "Artist": "Matt"}

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.

  • Paying bills. You would first collect bills then for each bill you would 1. Pay it and 2. mark the payment in your checkbook. Then repeat with all other bills.

  • Reveiwing movies. First you collect the movies then for each movie you would 1. Watch it and 2. write your review. Repeat with all other movies.

  • Building furniture. First you collect the parts and then for each part you would 1. Put it in the correct place and 2. screw it in. Then repeat with all other parts.

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

  • Determining a customer's age. First you collect birth year and for each birth year you would subtract from 2019 and repeat with all other birth years.

  • Finding the revenue of products. First collect the dollar amount in sales of each product, for each dollar amount subract the cost of buying that number of products, repeat with all other products.

  • Reviewing sales employees based on their sales. Collect the sales number for each employee, give each sales number a score, repeat with all other sales numbers.

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... round brackets were used around "student" instead of curly brackets
.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...no hyphen between sans-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...min(score) is used instead of max(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 is used instead of a == 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...Initialize is spelled 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:

  1. I followed all of the steps in the modify bash profile section but my command prompt looks the same.
@damwhit
Copy link

damwhit commented Jul 3, 2019

@cammac60 nice work on this!

Regarding your comment above, did you exit out of terminal and reopen it? I would run through the video again to make sure you hit all of the steps. If that doesn't work, can you send me a screenshot of your terminal prompt?

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