Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save StarPerfect/27f84ea762f8f2bf4f3e1b5e25d28b41 to your computer and use it in GitHub Desktop.
Save StarPerfect/27f84ea762f8f2bf4f3e1b5e25d28b41 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 (75 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 erases the first items in an array up to and including the value passed as the arguement. For example array.drop(5) will remove the first 5 array items, items indexed 0-4. If array = [a, b, c, d, e] and array.drop(2) the new output of array would be [c, d, e]

  • What did you Google to help you with this task, and how did you pick your results? I googled "Ruby drop method" and I looked at results from the ruby-doc.org site. I also noted that most of the results on the first page mentioned the same explanation as the link provided so it's safe to assume that is the correct definition of Drop.

  • In your own words, what does the Ruby array push method do? As you're explaining, be sure to provide an example. Your answer: The push array method just adds the argument passed to the end of the array. This method can be chained to add multiple items. For example: Say I have array = [-1, 0] . array.push(1).push(2) will add these to the end giving this output: [-1, 0, 1, 2]

  • What did you Google to help you with this task, and how did you pick your results? I googled "Ruby array push" and looked at the first few results and if I see the same answer then I use it.

  • 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 splits the string into pieces depending on the delimiter argument provided. "Corina Rae Allen".split(' ') would give the array ["Corina ", "Rae ", "Allen"]

  • What did you Google to help you with this task, and how did you pick your results? Googled "Ruby string split method" at the top of the results page was almost a definition from spin.atmonicobject.com which leads me to believe the split method is used often although I saw some other arguments passed which I did not quite understand.

  • In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer: JavaScript slice method removes array items. Arguments passed are where to begin which is optional, and wehre to end. If I have array = [1, 2, 3, 4] and I pass array.slice(1,2) then it will remove items beginning with 1 and ending at 2. Note in JavaScript the index begins at 1 not at 0. If I only passed array.slice(3) then it assumes to begin at the very start of the array and remove items up to and including 3. This would return an output of [4].

  • What did you Google to help you with this task, and how did you pick your results? Googled "JavaScript array slice" and the second result was from developer.mozilla.org so I trusted that site.

  • In your own words, what does the JavaScript object values method do? As you're explaining, be sure to provide an example. Your answer: JavaScript's object.values method returns an array listing the values within the object. For example if I have const corina = { a: 37, b: "blonde", c: "female"} and run object.values{corina) I will get the following array [37, "blonde", "female"]

  • What did you Google to help you with this task, and how did you pick your results? Googled "JavaScript object values" which again gave a definition like result at the top. The second result was from developer.mozilla.org so I confirmed the top result with mozilla's site before answering the question.

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: player tokens property names Chance or Community Chest instructions
  2. Integer and/or float data: Bank money player money hotels and houses
  3. Boolean data: If player lands on property: "Is property owned?" if no: "do you want to purchase?" if yes: "are there houses or hotels on the property?" This is to determine how much rent is owed to the property owner.
  4. Array data: Dice roll sets for example [1,1] [1,2] [1,3] etc Property ownership for example Corina = [ "Vermont Ave", "Oriental Ave"]
  5. Hash or Object data: Property rent for example Oriental_Ave = {"one_house" => 30, "two_houses" => 90, "three_houses" => 270, "four_houses" => 400, "hotel" => 550} Hash of price to sell property back to the bank

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.

  • Using public transportation to get somewhere, especially when it requires multiple buses or light rails. I usually check the schedule before I leave to figure out the best route to get me where I need to go by a certain time. Then I select the route and update it a few times before I actually leave to ensure there hasn't been any changes. Once I am ready to leave I check to make sure the first connection is on time, then walk to get there. Once I arrive I check to see how long until the bus comes. Then I board the bus. I check to see where to get off. Once I am there I depart, check to see where I go to get on my connecting bus, walk there, check the time until the next bus arrives, and repeat the process until I get on the last connecting bus. Then i check to see where I get off and once I arrive there, I walk to my destination.

  • Painting my nails would be iteration. Once I select the nail polish, I repeat the nail painting process for each finger or toe until all ten are complete.

  • Every week day is iteration in a way. I wake up at the same time, get ready for the day, commute for an hour to work, if it's M, W, or F I attend a meeting after work before going home. If it's a T or Th, I head straight home for our Mod 0 session. After the meeting or session, I prep the next days breakfast, get ready for bed, go to sleep and repeat until Saturday.

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

  • Say we have 30 new students in 1906 BE and want to print "Welcome" and each students name on the screen on the first day of class. We would write a little program to prints "Welcome #{student_name}!" for each student.

  • Maybe we have a clock program that sounds every hour on the hour. This would be a program of iteration, playing a sound if a boolean yes is returned to the programmed question "Has it been 59 minutes since the last sound?"

  • A chat program would be a sort of iteration. Every time a user in the chat sends a message the screen or page refreshes with the new message text.

4. 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:

@katiescruggs
Copy link

Good job, @StarPerfect! For your iteration examples, make sure you are starting with a collection. Your example of a clock sounding every hour is not iteration because a collection is not being looped over. Instead a program is doing something on an interval. Your example of a chat program is not iteration because a collection is not being looped over. Instead a program is responding to user inputs.

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