Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save peeratmac/eb4cd1e11df9f016c503e226e614640b to your computer and use it in GitHub Desktop.
Save peeratmac/eb4cd1e11df9f016c503e226e614640b 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 language, 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: Ruby array drop the first n elements from array and return the rest of the elements in an array. Example: an array a of number 1 through 1 drop notation would be a.drop(7) and the return would be [8, 9, 10] since the first 7 numbers got dropped.

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

  • Google was able to verify my understanding from reading ruby-doc link provided with a second set of explanation and 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: Ruby array push appends give objects on to the end of array specified. Example: a.push(11).push(12) and the return would be that array from 1 through 10 that would now include 11, 12 at the end.

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

  • I used another site that is high up in the search result and seems to have a section for just Ruby definitions.

  • In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example.

  • Your answer: Ruby string split separate string into substrings based on a delimiter, the return is array of the substrings. Example: "what time is it".split() would get a return of ["what", "time", "is", "it"]

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

  • Google was able to find examples of different delimiters used for split method. The results were picked by content relevancy with Ruby.

  • In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example.

  • Your answer: Slice method takes up to two arugemnts from beginning array index to ending index with ending index not being included in the result. Example: if it's an array of 1 through 10, console.log(a.slice(7, 10)) the output woudld be [8, 9] because index 7 would be number 8 and then 9, with 10 being the ending index.

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

  • I looked for another site for more examples and combined that with document by Mozilla to come up with 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: JavaScript object values returns an array of that object enumerable property values. Example: this car has a make value of a Subaru, a year value of 2018, and a color of blue. Object.values(car) would return Array ["subaru", "2018", "blue"]

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

  • Google was again proved to help with more examples until I'm more comfortable of knowing what to expect when using Object.values() method. The result was picked based on reading on multiple sites and tried to put that in words I can understand.

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: name of player, dice roll (how many spots to move), properties name
  2. Integer and/or float data: number of players, amount of money in the bank, number of houses owned
  3. Boolean data: owner of property A, bankruptcy, go to jail
  4. Array data: array of properties owned, array of properties with 2 houses or more
  5. Hash or Object data: property (title deeds), cards (community cards players draw)

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.

  • Weekday morning iteration, wake up in the morning, if hungry then make food, otherwise shower and go to work. Next morning, repeat with waking up and make food if hungry, otherwise shower and then go to work again. Repeat the same thing Monday through Friday.

  • Charging my phone, each day when my phone drops below 50%, find a charger to plug in, do it until 100% (time permitted) and continue to be able to use the phone with power as we find a charger each time it drops below 50%.

  • Baking cookies in batches, each time a 30-minute timer go off, remove the current batch from the oven and bake the new batch, start the timer again, repeat until all the cookies are gone.

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

  • Looking for 5 counts of random cities around the world to list out for users to visit, it would look for list of cities we have and out put 5 diffrent cities and then stopped looking until user click to generate another 5 each time.

  • If users want us to list the cheapest cheddar cheese available in the area, it might go through a database searching for lowest value in dollar amount for cheddar cheese.

  • A program going through a checklist for each customer to make sure they have enough credits, less than maximum allowed number of books, and is a current member in order to check out a new book.

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:

  1. N/A
@katiescruggs
Copy link

Nice work, @peeratmac! For your programming iteration examples, make sure that there is a collection / array you are looping over. For the example of finding the cheapest cheddar cheese, the collection is a list of different products with their prices, but for the other two examples, I'm not sure what the collection would be.

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