Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tbierwirth/acf5ca3de703cf256300d4d0c7e8acd8 to your computer and use it in GitHub Desktop.
Save tbierwirth/acf5ca3de703cf256300d4d0c7e8acd8 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: Drops first n elements in an array and reurns remaining elements in an array.
a = [7, 8, 9, 10] 
a.drop(2)
#=> [9, 10]
  • What did you Google to help you with this task, and how did you pick your results? I searched 'Ruby drop method' and chose a website that was concise that included an example.

  • In your own words, what does the Ruby array push method do? As you're explaining, be sure to provide an example. Your answer: Push method appends an element(s) to the end of an array.

a = [ "x", "y", "z" ]
a.push("a", "b", "c"
#=> ["x", "y", "z", "a", "b", "c"]
  • What did you Google to help you with this task, and how did you pick your results? I searched 'Ruby array push' and picked a result that was concise.
  • 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 split method separates a string and pararmeters can be set to separate it in a certain way
"hello world".split
  #=> ["hello", "world"]
"cheese".split(//)
  #=> ["c", "h", "e", "e", "s", "e"]
  • What did you Google to help you with this task, and how did you pick your results? I searched 'Ruby string split method" and ended up chosing the original documentation because it made more sense an I liked the examples.
  • 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 array slice method creates a new array from an orginial array.
var animals = ["Squid", "Cat", "Dog", "Chameleon"];
var mammals = animals.slice(1, 2);
  • What did you Google to help you with this task, and how did you pick your results? I searched 'Javascript array slice' and chose W3Schools as they had a simple explanation and example.
  • In your own words, what does the JavaScript object values method do? As you're explaining, be sure to provide an example. Your answer: The object.values method creates an array based on the object's property values.
const obj1 = {
  a: true,
  b: 'test',
  c: 15
};

console.log(Object.values(obj1));
#=> [true, "test", 15]
  • What did you Google to help you with this task, and how did you pick your results? I searched 'javascript object values method' and chose the original documentation because it was a simple explanation.

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

  • 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: "Brick", "Lumber", "Ore, "Wheat", "Grain", "Settlement"
  2. Integer and/or float data: Number of brick owned. Number of settlements placed.
  3. Boolean data: Does a player have 'longest road'?
  4. Array data: Longest road, number of ore, resource needed most [true, 3, "wheat"]
  5. Hash or Object data: If a player rolls a 7, the robber must be moved to a new hex.

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.

  • Following a recipe in the kitchen. You aquire an ingredient, reference the recipe, prepare accordingly and then set aside until all ingredients are prepared and you're ready to start cooking. This is iteration because the process is repeating until all ingredients have been used.

  • Sorting reclying at a processing facility. Worker picks up an item, determines what bin it should go in, places it that bin and repeats until all items are gone. This is iteration because the process repeats until the worker has gone through all items.

  • Cleaning dirty dishes. Person picks up a dirty dish, applies soap and scrubs the dish, rinse off and place on drying rack and repeat until all dishes are clean. This is iteration because the person is repeating the process of cleaning until all dishes have been cleaned.

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

  • Assigned seating on a plane. Find passenger who checked in first, assign their seat closest to the front, notify passenger and repeat until all passengers have been placed. This is iteration because each passenger is being assigned using the same process and repeats until all passengers have been placed.

  • Sorting a list of students based on birthday. Choose an unsorted students, reference birth date, place on list from oldest to youngest, repeat until all students have been placed. This is iteration because it's repeating a process of sorting based on birth date until all students have been sorted.

  • Assigning truckers jobs based on distance to job. Choose an available trucker, discover location, assign closest job and repeat until all jobs have been assigned. This is iteration because it's repeating a method of assigning jobs to truckers until all jobs have been assigned.

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

Nice work, @tbierwirth! Great examples of iteration!

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