Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save slkarsh/1cc412c3ebf689cc83a7045939be3f55 to your computer and use it in GitHub Desktop.
Save slkarsh/1cc412c3ebf689cc83a7045939be3f55 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:

This tells Ruby to return the content of an array, less n. n is a certain number of elements from the start of the array. Examples openedLanes : [1, 6, 9, 10, 12, 14] openedLanes.drop(3) would return [10, 12, 14] and the first three elements of the array are "dropped"

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

    I Googled both "ruby array drop method" and "drop method ruby." I found "drop method ruby" to be more helpful. I found a couple of results that said very similar things, but ultimately dove deeper into the page that explained the concept in the most straightforward terms and provided examples, so there was a visual component to compliment the concept.

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

Your answer: this adds items to the end of an existing array (or "pushes" them into the array) Example: openedLanes : [1, 6, 9, 10, 12, 14] openedLanes.push : [2, 7, 11] this would return openedLanes : [1, 6, 9, 10, 12, 14, 2, 7, 11]

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

    I Googled "push method ruby." The result I ended up looking at was through API Dock, which matched the ruby-doc.org description. I also looked at an example on StackOverflow and a question and answer on CodeCademy. I focused on the answers that kept it simple - an easy to digest description and a basic code example.

  • In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer: this splits strings into component parts, and it does so in different ways depending on how you want the string split. The return is an array of the elements of the split string.

Examples:

"Hello World".split #=> ["Hello" , "World"]

"Hello World".split(//) #=> ["H", "e" , "l" , "l","o","","W","o","r","l","d"]

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

    I searched "split string ruby" and a lot of what came back was similar or identical to the resource provided. I searched in StackOverflow as well, and while I didn't find exactly what I was looking for, I found some questions using split and example code, which helped my understanding.

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

Your answer: This takes certain elements from an existing array and outputs them to a new array (what is "sliced" is kept in the array. If an element is not sliced, it is removed from the array). There can be a beginning point and an end point. If a beginning point is not defined, the slice begins at index 0 (the first element of the array). If the end point is not defined, the slice goes from the beginning point to the end of the array. When an end point is provided, the slice goes up to but not including the end index. So, slice(1,5) would produce a new array consisting of elements from positions 1, 2, 3, and 4, but not 5.

Examples: var lanesOpened = [4, 7, 8, 11, 14] console.log(lanesOpened.slice(1,3)); expected output array : [7,8]

console.log(lanesOpened.slice(0,3)); expected output array : [4,7,8]

console.log(lanesOpened.slice(0,-1)); expected output array " [4,7,8]

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

I Googled "slice javascript." To be honest, the answer on Mozilla Developer was the most helpful, especially after reading through the page in its entirety a couple of times. Besides that, from my search I looked at a couple of other code examples to make sure I understood the fundamental concept and also at a post on StackOverflow where a user was essentially asking how to create a new array from an existing one and the top answer showed a basic use of the slice code.

  • In your own words, what does the JavaScript object values method do? As you're explaining, be sure to provide an example. Your answer: this takes the values of an object and returns them in an array. For example:

var Oliver ={ age : 1 breed: lab legs: four }' console.log(object.values(oliver)); would return Array [1, lab, four]

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

I Googled Javascript object values method. I cycled through pages after reading the description from Mozilla Developer that had generally similar code examples to the ones from Mozilla, and then read through those examples and explanations extensively. I also tried googling "enumerability javascript" to figure out the difference between an enumerable object and an object that is not enumerable, but I don't think I have enough baseline knowledge to understand what would make an object non-enumerable.

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

  • 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: Player name ["Sara", "John", "Dave", "Aaron"] Property names ["Park Place", "Connecticut Ave", "New York Avenue"]

  2. Integer and/or float data: total number of spaces, number of spaces moved per turn, number of hotels per property, money per player

  3. Boolean data: does this property have a hotel? Does this property have a house? Did the player land on “go”? Did the player pass “go”?

  4. Array data: Properties [Park Place, NY Ave, Connecticut Ave, etc] Playing piece [thimble, cannon, top hat, horse]

  5. Hash or Object data: Property name and number of hotels on property [Vermont Ave: 2] Color group and properties in the color group [light blue : “Connecticut Ave” , “Vermont Ave” , “Oriental Ave”]

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.

    1. Opening new files at my current job (paralegal). Collection: new client files For each new client file,
      1. Input client data
      2. Input insurance data
      3. Generate insurance letters of representation
      4. Generate client letters of representation And repeat until all new client files were opened. This is an example of iteration because each step must be completed before the next one can take place, and once all the tasks are complete I'm able to move onto the next file. Each item in the collection requires the same steps to take place before the next item in the collection can be addressed.
    1. Using the self checkout at the grocery store. Collection: grocery items Steps:
      1. Scan item
      2. Place into bagging area Repeat until all items have been scanned and bagged, and then make payment. This is iteration because both steps have to be done to every single item before the loop can be broken and the next step (making payment) can take place
    1. The job of a hairstylist. Collection: clients For each client, steps would be:
      1. Discuss client's request
      2. Wash hair
      3. Cut hair
      4. Style hair
      5. Take customer to checkout This must be done for every single client appointment (at least standard hair cut appointment) to completion until all of the clients in the collection have been addressed.
  • 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.

    1. Determine if user of website needs reminder to complete registration Collection: new users Steps:
      1. Determine if username established
      2. Determine if email address confirmed
      3. Determine if profile completed Repeat for all new users This is iteration because it takes a subset of information (the array of new users) and cycles through the steps required to finalize the registration of an account and does this continually for new users, until everyone on the new user list has been addressed.
    1. Determine if students need an attendance warning via in-school messaging Collection: students For each student:

      1. Count number of absences over the last month
      2. Determine average number of absences per week
      3. Send automated attendance email to students and families Repeat for all students

      This is iteration as the program goes through the data available for every element within the array [students] and the task is complete when each item in the collection has been reviewed.

    1. Application updates on phone Collection: apps on my phone For each app:

      1. Check for an update
      2. Confirm software compatability
      3. Complete update Repeat for all apps until no apps remain

      This is a finite number of elements in the collection and probably a fairly simple example of iteration, but the app store must cycle through all of the apps I have to determine which ones need to be updated depending on update availability

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

Great job, @slkarsh! Really like how you made your iteration examples so clear by starting with a collection and showing the steps for each item in that collection.

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