Skip to content

Instantly share code, notes, and snippets.

@ckoga
Forked from rwarbelow/mod_0_session_2_practice_tasks.md
Last active March 21, 2019 01:37
Show Gist options
  • Select an option

  • Save ckoga/f1d2fbf4c69b867d62bb5f55356ea8fe to your computer and use it in GitHub Desktop.

Select an option

Save ckoga/f1d2fbf4c69b867d62bb5f55356ea8fe 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 array method will drop elements up to the specified value and return the rest of the elements to the array. ex. sandwich = [lettuce, tomatoe, mayo, cheese, turkey] if you input sandwich.drop(mayo) you should be left with [cheese, turkey]

  • What did you Google to help you with this task, and how did you pick your results? I ran multiple searches as google didn't recognize "array drop method Ruby". From rewording like Ruby drop method, to drop elements from array. The other thing I tried to pay close attention to was the time stamp for each page, it was interesting to me that the older the article the easier it was for me to understand the explanation. Going forward into actually writing code I would most likely never use older sources but I'm hoping since explanations from 2012 are almost identical to posts from 2017 I'm not too far off from my understanind of the Ruby drop array 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 array method will add an element to the end of your array, this can be done with more than one element. ex. sandwich = [lettuce, tomatoe, mayo, cheese, turkey] can be added to by putting sandwich.push(onions, pickels, mustard) to get sandwich = [lettuce, tomatoe, mayo, cheese, turkey, onions, pickel, mustard]

  • What did you Google to help you with this task, and how did you pick your results? I spent a lot less time googling this term as some of the sites I found for the drop array method also explained the push method. But to make sure I wasn't missing anything I ran two additional searches push array method and push elements array ruby. The first search resulted in a lot of JavaScript answers, while the second brought up many articles I had previously seen for the drop array method.

  • 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 string method will take a string and break it down according to the limits specified in the command. A normal splt will look like this. If the string is "excited for Turing" we can split it by inputing "excited for turing".split and it will yield #=> ["excited", "for", "turing"]

  • What did you Google to help you with this task, and how did you pick your results? I probably spent too much time on this one. I googled split string, ruby split string, splitting string, and a few others. I think I read the same thing spread across multiple sources and still only have the basic grasp of this idea.

  • 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 JavaScrpit array slice method allows you to remove specified elements from an array. For instance var food = ['vegetables', 'cheese', 'fruits', 'bread', 'meat'] then say var favorite foods = foods.slice(1, 2, 4) and the expected outcome is cheese, fruits, meat.

  • What did you Google to help you with this task, and how did you pick your results? This one was easier to understand so I only googled javascript slice array. Not only did I find the site linked in the assignment the top three sites were posted in the last two years alleviating some doubt to thier relevance.

  • 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 Javascript object method takes numbered values from an array and returns their values in an array. An example would be var obj = { 0: 'car', 1: 'bike', 2: 'train'}; console.log(Object.values(obj)); // ['car', 'bike', 'train'] Object values can also be reorganized into an specific order. If the values aren't listed in order like var an_obj = {7: 'skates', 5: 'longboard', 6: 'moped'}; console.log(Object.values(anj_obj)); // ['longboard', 'moped', 'skates']

  • What did you Google to help you with this task, and how did you pick your results? Anther method I feel like I only brushed the surface of, I searched a few different phrases to try to better understand object values. Javascript object values explained yielded the best answers for me, the top three results were posted within the last 2 years.

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: Escape "The Curse of the Temple"

  • 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:"Roll dice and cooperate with other players to escape the dungeon." "Beware you must escape the dungeon before the time runs out!"
  2. Integer and/or float data: Maximum number of players "5" Play time in minutes "10"
  3. Boolean data: In order to move pieces on the board you must roll a specified combination of symbols. If you do not roll this combination of symbols you cannot move forward.
  4. Array data: Dice faces ["running man", "key", "torch", "curse mask", "golden mask"] Game contents ["board", "dice", "timer", "player icon", "jewels", "modifier cards", "jewels"]
  5. Hash or Object data: {"board cards": 19, "dice": 30, "player icon": 5, "jewels": 100, "modifier cards": 14} {"Start point cards": 6, "cards with 2 doors": 4, "cards with 1 door": 3, "cards with 3 doors": 3, "cards with 4 doors": 4}

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.

  • Restraunts is an example of real life iteration. To use the format from session 2 the collection could be tables, for each table you take an order, prepare/serve food, clean the table and repeat.

  • Doing laundry is another example. each load can be considered the collection, for each piece of clothing you will fold, sort by type and put away. On to the next load of laundry.

  • Food prep for the week can also be considered an iteration. For one week you need to plan, buy ingredients, prepare ingredients, cook, and store food. Once the food is finished repeate.

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

  • Email CC I think is an example of iteration in programming. Take a collection of contacts, write an email, the email client will then attach the email to each address and send to the corresponding contact.

  • Calculating expenses for a month. The collection would be your budget. For each week collect reciepts, add up the total and subtract from your set budget for the month. repeat each month.

  • Alphabetizing a student roster. The collection would be the names of students in class. For each student take the last name and determine its relation to the letter A then move to the next student.

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, @ckoga!

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