Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ksandy95/fd12c80df3102d5a4833c8dd2ce90a4f to your computer and use it in GitHub Desktop.

Select an option

Save ksandy95/fd12c80df3102d5a4833c8dd2ce90a4f 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 Ruby .drop method is used to return a collection except for the forst 'n' number of things being dropped. An example of this would be if i had a list of pets and didnt want the forst 3 to be used in the return i wanted.

  • What did you Google to help you with this task, and how did you pick your results? To find this answer i googled "ruby" + ".drop" I went through the first 3 links to get a good understanding for the 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 method is used to add an object to the end of an array. An example of this could be adding strings into a pre existing list of names.

  • What did you Google to help you with this task, and how did you pick your results? I googled "ruby" + ".push" example. The first few results werent very helpful, however after some looking a stack overflow and codecademy resource were able to explain it well.

  • In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer: string split makes it possible to break up a string into substrings. This sould be useful if instead of having individual strings in an array, you had one string with each sub string separated by a ,. the split would then break that into many.

  • What did you Google to help you with this task, and how did you pick your results? For this exercise i googled "ruby" + "string split" example. There was a relevant stack overflow thread that detailed the uses for split well.

  • In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer: slice is almost the opposite of push. Instead of adding things to an existing array for a 1 off addition, slice removes select things from an existing array without changing the array perminantly as a 1 off.

  • What did you Google to help you with this task, and how did you pick your results? I used the link provided as well as (slice) javascript example in my google search. It was pretty straight forward there were many threads available using it. I used the geeks4geeks examples to help with my understanding.

  • In your own words, what does the JavaScript object values method do? As you're explaining, be sure to provide an example. Your answer: .values is used almost exclusively for arrays, or array like objects in javascript. IT will return the properties or the array or object it is being used on. It is used in many checks and tests to double check your array or object is returning what it is supposed to be returning.

  • What did you Google to help you with this task, and how did you pick your results? I googled javascript .values example as well as javascript .values meaning I picked my results by going through the first 4 web page results. the first 2 didnt make much sense or give a good example for someone unfamiliar with javascript to understand. But geeksforgeeks was able to provide good examples to learn from.

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: Chutes and Ladders

  • 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 players, Game prompts
  2. Integer and/or float data: number of cells on board, precentage completed.
  3. Boolean data: chute (yes/no), ladder (yes/no), winner (yes/no)
  4. Array data: Spinner options, cell connections between chutes and ladders?
  5. Hash or Object data: mapping ( a hash of attributes to represent tiles), cells

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.

  • Laundry, it is a cycle process that never truly ends.

  • Garbage, it is also a cycle process that never ends.

  • The act of life. We wake up, we live, we sleep.

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

  • a loop getting user imput requiring a certain type of response. get.chomp users age. It will continue to ask until an integer is submitted.

  • virus scanners, they use iteration to track changes to a computer and identify if they are unsafe or not.

  • ad block it uses iteration to keep annoying advertisements off of your screen by continuiously scanning for them.

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: None to add thank you!

@katiescruggs
Copy link

Nice work, @ksandy95! For your iteration examples, make sure that you are thinking about a collection. Most of your examples are endless loops, but iteration will stop once each item in the collection has been gone over. For example, with the laundry example, your collection could be clean items of clothing. For each item of clean clothing, fold it and place it in the drawer. Then move on to the next item. Does that make sense?

@ksandy95
Copy link
Author

ksandy95 commented Apr 9, 2019

Yes thank you for the feedback! Should I adjust my examples in this assignment? :) The video lesson yesterday cleared up some understanding gaps as well for iteration.

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