Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save tschaffer1618/06aeb3eb4e2627135f3f1d9fdbe64be8 to your computer and use it in GitHub Desktop.

Select an option

Save tschaffer1618/06aeb3eb4e2627135f3f1d9fdbe64be8 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.

The drop method for an array removes the specified number of items from the array starting with the first item. Once the specified number of items are dropped, the remaining items are returned in the array. (Ex: array = [1, 3, 5, 7, 9, 11, 13]; array.drop(5) => [11, 13])

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

I googled 'drop method array ruby' (not in quotes) and chose to look at https://guide.freecodecamp.org/ruby/common-array-methods/ because I had already looked at the ruby docs and this seemed to match my search most closely.

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

The push method for an array adds the specified items to the end of the array. Similar methods include .pop, .unshift, and .shift, depending on if you are adding/removing items from the beginning/end of the array. (Ex: array = [2, 3, 5, 7, 11, 13]; array.push(17, 19) => [2, 3, 5, 7, 11, 13, 17, 19]

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

I googled 'push method array ruby' (not in quotes) and checked several of the links based on matching search criteria and date of the link.

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

The split method for a string divides the string into substrings and returns those substrings in an array. There are many possible variations (delimiters) for splitting the string depending on if you want to subdivide into words, letters, spaces, etc. (Ex: "Prime numbers are fun".split => ["Prime", "numbers", "are", "fun"])

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

I started with 'string split ruby' and then googled 'string split ruby delimiter' to get more info on the possible variations on the split method. The best explanation I found was at https://www.thoughtco.com/using-the-split-method-2907756 which is a recent and applicable article.

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

The slice method selects a portion of an array and returns it as a new array. In the format .slice(x, y), x is an integer that represents on which item the first boundary is set, and y is an integer that represents on which item the secondary boundary is set. Both boundaries are placed after the designated number of item. If x or y is not specified, the boundary is at the beginning or end of the original array, respectively. The returned array contains the items between the 2 set boundaries. (Ex: var vowels = ['a', 'e', 'i', 'o', 'u']; vowels.slice(2, 4) => ['i', 'o'])

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

I began with the mozilla docs, and then googled 'javascript array slice method.' I chose what looked like a pertinent link based on keywords and url (not w3schools, mainly) to provide more clarification (http://www.javascripttutorial.net/javascript-array-slice/).

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

The values method for an object looks at the list of properties the object has, and returns the values of those properties in order in an array. (Ex: let dog = {name: 'Fido', age: 8, breed: 'poodle'}; Object.values(dog) => ["Fido", 8, "poodle"]

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

I googled 'javascript object values method,' and found 3 or 4 professional-looking and date-appropriate links that I used to help explain this concept (which I found to be much more confusing at first than the others).

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:

Names of the properties: "Virginia Avenue", "Reading Railroad", "Water Works", etc.

Chance/Community Chest cards: "Pay poor tax of $15", "Go to jail, go directly to jail, do not pass go, do not collect $200", etc.

  1. Integer and/or float data:

Dice roll sum: 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12

Cost to buy properties in monopoly dollars: 120, 200, 300, 400, etc.

Rent paid to owner of a property if landed on in monopoly dollars: 6, 10, 25, 50, etc.

  1. Boolean data:

Rolling doubles to get out of jail: true or false.

The property that I landed on is unowned: true or false.

  1. Array data:

Property groups: Blue_properties = ["Park Place", "Boardwalk"], Railroads = ["Reading Railroad", "B & O Railroad", "Short Line", "Pennsylvania Railroad"]

Contributors to free parking (house rules): Free_parking = ["Luxury Tax", "Jail Money", "Property Tax", "Other Taxes"]

  1. Hash or Object data:

Name of property (key) and its cost to buy (value): {"Park Place": 350, "Boardwalk": 400}

Name of player (key) and their chosen playing token (value): {"Bob": "Thimble", "Jane": "Race car", "Stacy": "Hat")

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.

  • Scenario: Photo Editing (collection: photos)

    For each photo, (1)crop/resize the photo, (2)adjust the lighting, and (3)remove red eye. Repeat the steps with each photo.

  • Scenario: Eating Lunch (collection: bites)

    For each bite, (1)cut the bite, (2)stab the bite with a fork, (3)bring the bite to your mouth, (4)chew, and (5)swallow. Repeat the steps for each bite.

  • Scenario: Programming Radios (collection: radios)

    For each radio, (1)unpack the radio, (2)add company sticker, (3)attach battery, (4)plug into computer, (5)hit "clone radio" button, (6)unplug radio from computer, and (7)repack the radio. Repeat the steps for each radio.

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

  • Scenario: Checking Password (collection: password attempts)

    For each password attempt, (1)compare the attempt to the stored password. If the attempt is not identical to the stored password, (2)request another password attempt. Repeat steps 1 and 2 until the attempt is identical to the stored password, and end iteration.

  • Scenario: Formatting File Names (collection: file names)

    For each file name, (1)make all letters lower-case, and (2)replace any spaces with underlines. Repeat the steps with all file names.

  • Scenario: Calculating Final Grades (collection: students)

    For each student, (1)average the scores of his/her tests from each quarter to get a quarterly grade, and (2)average the quarterly scores to get a final grade. Repeat the steps for each 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, @tschaffer1618! Good iteration examples. I like how you made them so clear by listing the collection! Your checking password example isn't quite iteration since it's waiting for user input. You can tell that it's not like the others because it ends with Repeat steps 1 and 2 until the attempt is identical to the stored password, and end iteration. instead of Repeat the steps with all [collection-item-here]. like your other examples.

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