Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save sirsaw/03a9f0a1e716b73fff3d5ba4148b5e0d to your computer and use it in GitHub Desktop.

Select an option

Save sirsaw/03a9f0a1e716b73fff3d5ba4148b5e0d 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 ("drop(n) → new_ary") will take an existing array, remove the specified number of items from the array (n), and then return the newly altered array.

  • What did you Google to help you with this task, and how did you pick your results? I Googled "Ruby array drop functionality" and just looked at a few results. They mostly had similar info.

  • 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 will allow you to take an existing string and cut it into separate smaller strings. This can be done in varying ways, based on length, or a key character, from what I understood.

  • What did you Google to help you with this task, and how did you pick your results? I googled "ruby string split functionality" and went with a blog post that was the 2nd or 3rd result. It was explaining how to use it for new people.

  • In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer: The JavaScript array slice funtion will take an existing array, and based on parameters you provide, will create a new array from what was contained in the original array.

  • What did you Google to help you with this task, and how did you pick your results? I googled "how does javascript array slice work" then I read the results on W3schools and wikipedia since they seemed the most basic and straightforward.

Side note: I don't actually know these programming languages, like most people in class at this point, I assume. Reading about, deciphering, and explaining their functionality feels fairly fruitless. Without deeper knowledge, I don't have much sense of direction to refine my searches, nor any context to determine if what I'm reading is relevant or accurate. Practicing Googling for answers when I don't even know the right question to ask feels like putting the cart before the horse.

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: The Game of 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: Profession, Address, Car Color
  2. Integer and/or float data: Income, Loan Amount, Rent, Number of Children
  3. Boolean data: Married? True/False // Graduated college? True/false
  4. Array data: Life Tiles (integers)
  5. Hash or Object data: Number of Children (integer)

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.

  • Mowing lawns: For each lawn, mow the lawn, trim the edges, and throw the clippings in the trash, then move to the next lawn. This is an example of iteration because the same steps are being used on each lawn.

  • Washing dishes: For each dish, scrub it with a soapy sponge, rinse it with water, then set it aside to dry. This is an example of iteration because the same steps are being done to each dish.

  • Doing laundry. For each article of clothing, put it in the washing machine, then the dryer, then fold it, then put it away in the dresser. This is an example of iteration because the same steps are being done to each article of clothing.

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

  • Formatting database names. For each user namne, capitalize the first letter, then make all the following letters lowercase. This could be an example of iteration that needs to be done to make data consistent, so you don't have some names in all caps or all lowercase.

  • wsfgynaiokldm ugiuvm;la,.

  • Using iteration, you could check the birthdate of everyone in a database each day, and send automated happy birthday messages on each person's actual birthday. It could perform a boolean check on each person to see if it was their birthday.

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 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 dash in 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... wrote min instead of max
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... wrote "b == b" intead 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... misspelled initialize

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 3, 2019

@sirsaw great job on this for the most part..

For the programming iteration examples, think through what granular data manipulation would need to happen. You did a great job of this in the first example. I would encourage you to try the same for the next two.

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