Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save julianenochs/aa119fb72f4fc4440c1664d34a3e972f to your computer and use it in GitHub Desktop.
Save julianenochs/aa119fb72f4fc4440c1664d34a3e972f 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 will go through an array until the index (n) is found, it will drop that index and then return the array. [2,4,6,8].drop(6)

  • What did you Google to help you with this task, and how did you pick your results? I googled the phrase "array drop method ruby" and went through several options. Stackflow did not specify the drop method but a blog that was titled "Learn How to Use Ruby Arrays in Less Than 10 Minutes" specified this method.

  • 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 method will add an additional array to the end of a given array specified as index.push An example would be jello = ["pudding", "yogurt", "mayonnaise"] jello.push("jam", "jelly") #=>["pudding", "yogurt", "mayonnaise", "jam", "jelly"]

  • What did you Google to help you with this task, and how did you pick your results? I googled the phrase "array push method" and did not find a more concise answer than the ruby-doc explanation so that is what I chose.

  • 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 will separate strings based on a delimiter. An example would be if the string is str= "take me, to church" and the delimiter is puts split.", " the split method would give you "take me" ", to church"

  • What did you Google to help you with this task, and how did you pick your results? I ultimately chose the blog thoughtco after looking at the ruby-doc and other resouces. Ruby-doc required too much previous knowledge that I don't have and the blog post was thorough enough for this purpose.

  • In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer: Using the slice method you will identify a portion of the slice via a specified index and the method will move through the array until that value is found. A new array will be formed starting from the specified index until the end of the original array. var jello=["grape", "cherry". "banana", "cheese"] console.log(jello.slice)=("2")) ["banana", "cheese]

  • What did you Google to help you with this task, and how did you pick your results? I used mozillas dev resource to define a slice, it was a clear and concise explanation.

  • 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 are names to properties associated with specified objects. An example would be: var beer = new object(); beer.type = 'Odd13' beer.price = '11' The values would be 'Odd13' and '11'

  • What did you Google to help you with this task, and how did you pick your results? The mozilla dev resource had a great explanation and example.

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: Settlers of 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: ["Resource" "Player color"]
  2. Integer and/or float data: points, victory points, number of settlements
  3. Boolean data: if number is rolled and settlement is placed, then resource will be collected. true and true = true if more than 7 cards are in your hand when a 7 is rolled, then you must forfit half of your cards.
  4. Array data: resources necessary to build a road, resources necessary to build a settlement.
  5. Hash or Object data: (player color : #of points)

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.

  • looking for your keys. You will continue to look in places that your keys would be until your keys are found

  • taking out the trash. You will fill an empty trash can until it is full, then take the trash out and put a new trash bag in the trash can.

  • deciding where to eat with your sig o. You will continue to ask each other where you want to eat until one person decides where to go.

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

  • searching for an index in an array

  • searching an app that lists restaurant names for specific requests

  • searching a database that has information from a school to look for student names and grades

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, @julianenochs! For the iteration examples, make sure you are thinking about a collection that is being iterated over. For your examples, it seems like it is a process that repeats until something happens. With iteration, the process repeats until it has been done for each item. Weird example that came into my head = collection: fingernails. For each fingernail, paint it. Does that make sense?

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