Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ayladharamsey/1a435da87f5f5ad2bd7b2696ed15058e to your computer and use it in GitHub Desktop.
Save ayladharamsey/1a435da87f5f5ad2bd7b2696ed15058e 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: A drop in a ruby array means that whatever value you put in the place for n is the number of elements that ruby will not return in the array. It will return whatever is left. For example, if I had an array of a = [4,5,6,7,8,9] and I told ruby to drop 2 by writing a.drop(2), the array result would be a=[6,7,8,9].

  • What did you Google to help you with this task, and how did you pick your results? I googled 'drop method + ruby' and selected results based on their hierachy on the google search, and what the site does in reference to ruby.

  • 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 essentially tags on whatever push value you input to the end of the array. So, if a=[1,2,3,4] and you pushed 8,9 by coding a.push(8,9), the array returned would be a=[1,2,3,4,8,9].

  • What did you Google to help you with this task, and how did you pick your results? I google array 'push + ruby'. I picked the result from ruby-doc because that is what I found helpful the last time.

  • In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer: When you have a string, meaning a phrase or partial sentence within the code, and you want to divide the string into each word separately, potentially adding spaces between each word, you can 'split' the string. For example: Ayla's Splitting Example.split ==> ["Ayla's" , "Splitting" , "Example"]

  • What did you Google to help you with this task, and how did you pick your results? I google 'Split Ruby String'

  • In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer: When slicing elements from arrays in Ruby, the Ruby array returned contains a shallow subset of the original array's elements. When slicing, it is important to know that you are working off of a 0-based scale, so the first element would be 0. Second element 1, and so on. It is also important to not when slicing that if you're providing a range, the first number is the first element where the slicing starts, but the second number is the number that it ends at, but does not encompass that number. So, if you has an array of a = [1,4,6,7,8] and sliced a few out using console.log(example.slice(1,4)) that it would return an array like a = [4,6,7] .

  • What did you Google to help you with this task, and how did you pick your results? I googled 'slicing javascript string' and read a few different pages that had dates of this year.

  • In your own words, what does the JavaScript object values method do? As you're explaining, be sure to provide an example. Your answer: In javascript, you can make objects by declaring various values and grouping them within an object. If you wanted an array of all of the values attached to an object, you could use the Object Values method.

Example:

var object = { 1: 'Pickles', 2: 'Pineapples', 3: 'Cucumbers' }; console.log(Object.values(object)); Output : Array ["Pickles", "Pineapples", "Cucumbers"]

  • What did you Google to help you with this task, and how did you pick your results? I searched 'Object Value Method Javascript 2019' and got very relevant information.

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: 'Pass go to collect $100' , 'Get out of jail free'

  2. Integer and/or float data: Each house price could be an integer example

  3. Boolean data:

var collect 100 = false; if (collect 100) { does not pass go }

var jail = false; if (jail) { obtains get out of jail free card }

  1. Array data: [buying, renting, selling]
  2. Hash or Object data:

var rental property = { price: M350 name: Park Place color: blue };

var purchased property = { price: M240 name: Illinois Place color: red };

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.

  • Mailing invitations, because of the repetitive process that does not major have deviations. 1) Pick up invitation, 2) Place invite into the envelope, 3) Address the envelope & place Stamp 4) Send Invite

  • Folding laundry. The process remains, pick up unfolded laundry, fold laundry, repeat until there is no laundry left. Simple, no deviations from the original process or extra conditions.

  • Roll call in class. Teacher goes down the roster and marks present or absent for each student until there are no more names to call. Again, another example of a process that is simple and clear cut, so it can be replicated easily.

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

  • Find / Replace function. You enter an example to 'find', and the computer matches the word you entered against each word, replacing the matching word as you go until there are no words left.

  • Deploying a site. A team could have a process or checklist that gets executed to determine if everything is ready for deployment. Each item on the check list is assessed, and as long as there are items to check and everything comes back true, then the loop continues until there are no more items on the list to check.

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 job, @ayladharamsey!

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