Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SamanthaLFreeman/6731aabc5f702be51c695e04eb112a49 to your computer and use it in GitHub Desktop.
Save SamanthaLFreeman/6731aabc5f702be51c695e04eb112a49 to your computer and use it in GitHub Desktop.
Mod 0 Session 2 Practice Tasks - Samantha Freeman

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 removes the first element(s) listed and returns the rest of the listed elements without the "dropped" elements. In the example, below you can also designate the number of elements dropped, so I dropped the first two. Example: (array) farm = ["cow", "pig", "horse", "sheep"] then the (drop method) farm.drop(2) creates = ["horse", "sheep"]

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

I googled "ruby array drop method" and clicked open multiple links. After reviewing the couple I opened, it seemed that ruby-doc.org was the best option for me. They had the simpliest answer to follow; even one of my other links APIdock.com just copied the definition word for word.

  • 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 can add an object or objects to the end of your array, so when you return the array it will list the original listed elements followed by the elements included in the push method. Example: (array) farm = ["cow", "pig", "horse", "sheep"] then the (push method) farm.push("chicken") creates ["cow", "pig", "horse", "sheep", "chicken"]

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

I tried to get different google results with "push array ruby". However, a lot of my results were similar to the previous method. Same as before I opened a couple different tabs and then tried to narrow down to the ones that seemed to fit the question. I did find a website called studytonight.com that had a simplified definition for a beginner like myself to understand.

  • 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 takes your string and splits it up into separate groups. You can use the split method to clarify how you want the string to be split up. In my example below, I'm asking it to split up the word into its individual characters. Example: (String with split method) "Chicken".split(//) creates ["C", "h", "i", "c", "k", "e", "n"]

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

I got trapped in a bit of a rabbit hole with the split method. There is just a lot of different ways to split, so I started finding myself a bit confused looking at all of the different options. So I went back to my original search "ruby string split method". Then looked through a couple of the top choices and focused on the basic functions. I used some stackoverflow examples to see how it actually worked.

  • 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 slice method creates an output where you can remove from the begining and/or end of an array. It's important to note that the count for the array starts at 0. In the example below, the slice reads the first number as "from" and the second number as "until". Example: (array) var farm = ["cow", "pig", "horse", "sheep", "chicken"]; then the (slice method) console.log(farm.slice(2,5)); creates Array ["horse", "sheep", "chicken"]

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

I searched "array slice javascript", then I skipped over the w3schools link and opened a couple different links below it. medium.freecodecamp.org had a very simplified description that also walked you through the index being zero. This made it easier for me to understand what the numbers were actually doing during this method.

  • 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 takes all of the values listed and combines them into one array (list) with the same order. Example: (object values) const farm = {a: "cow",b: "pig",c: "horse"}; then the (values method) console.log(Object.values(farm)); creates Array ["cow, "pig", "horse"]

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

I searched "Javascript object values method" and then opened up multiple articles that seemed pertaining to the question. Two of them were a bit wordy and didn't seem to be about the values method; so I removed them from the original list of tabs. I found a site called javatpoint.com, which was a bit long however had a lot of examples which helped with my understanding. I also liked that I could play with the code in mozzilla, which I also did for the slice method.

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: Ticket to Ride

  • 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: "Denver", "San Francisco", "Salt Lake City", "Orange", "Black", "Wild", etc
  2. Integer and/or float data: 1, 2, 3, 4, etc
  3. Boolean data: Does the player have enough of the same color cards to complete a route? Are all routes taken between San Francisco and Los Angeles?
  4. Array data: List of colors: ["Orange", "Black", "Wild"], List of open routes: ["Los Angeles-Las Vegas", "Los Angeles-Phoenix"]
  5. Hash or Object data: (card color, number in deck): {yellow, 12}, (route, number available): {"Seattle-Helena",1}

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.

  • Cleaning out any expired food in your fridge. You will need to review the expiration date for the food item and then repeat the task for the next piece of food in the fridge until you have reviewed all contents in the fridge.

  • Moving my Mod 0 homework tasks to the completed column in Github. I am opening up each checklist in GitHub that I have due and then once completed I move the task over to the completed column. Then I proceed with the next task in the to do column. I continue until I no longer see any homework assignments for Session 2.

  • Prepping food before cooking a meal. For example, for cooking soup I will chop up one carrot and then add to the soup pot. Then I would grab the next carrot and repeat the action. I would keep adding carrots until there are no more carrots available on the cutting board.

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

  • I believe search engines use iteration. By taking the phrase that you have searched and then comparing to a large number of websites checking to see if they reference a part or all of your phrase. They will stop once they've reviewed all of the pages and then present a list of their findings to the user.

  • Fitbit has reminders set up, where it checks if I am hitting my goals for the day. If I have not hit the goal it sends a reminders to start walking. Then it repeats the same check throughout the day. It continues to check until the time I have it set up to stop checking. Then it will repeat the task again the following morning.

  • In side scroller games, the game will repeat the level every time your character fails (i.e. falls off the ledge). It will then repeat the same level again until your character reaches the end of the level. Then the iteration ends and a new iteration starts with the next level.

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, @SamanthaLFreeman! All of your real-life iteration examples look great and have a clear collection that is being iterated over. For your programming example, it seems that those are loops that end when a condition is met (level repeat in video games) or things that run on a timer (fitbit reminders). Make sure that you think of a collection when coming up with programming examples too!

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