Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save N-Gibson/d2deed6a51b4f06f9a3bfcb504e27a54 to your computer and use it in GitHub Desktop.

Select an option

Save N-Gibson/d2deed6a51b4f06f9a3bfcb504e27a54 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: Ruby array drop removes (returns) a specified element. Ex. browsers=['chrome','firefox','safari'] a.drop(safari) #=>['chrome','firefox']

  • What did you Google to help you with this task, and how did you pick your results? I googled "Ruby array drop pseudocode" to find a simple explanation. I sifted through the results by looking for sites I recognize. There was a different explanation on ruby.doc.org that I found which was the most helpful to me.

  • In your own words, what does the Ruby array push method do? As you're explaining, be sure to provide an example. Your answer: Ruby array push method is a way to add items to the end of an array by creating strings to the original rather than modifying it. Ex. a=["apples","peaches","pears"] a.push ("oranges", "plums") #=>["apples","peaches","pears","oranges","plums"]

  • What did you Google to help you with this task, and how did you pick your results? I googled "example of push in Ruby," "Ruby push pseudocode," and "what does push in Ruby do." None of these searches were perticurlarly helpful, however, I was able to deduce the meaning based on the example and short definition provided.

  • In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer: Ruby string split cuts an array along a pre-defined string and returns an array of smaller sections or added information. Ex. ex="test1","test2","test3","test4" ex.split("//3").first ="test1" #=> ["test1","test2","test3test4"]

  • What did you Google to help you with this task, and how did you pick your results? I googled example of string split in Ruby and I looked on StackOverflow and made note of upvotes,a recent date, comments and whether or not the suggestion worked for the inital user.

  • In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer: JavaScript array slice copies a portion of an array into a new array without changing the original array (excludes the begining and end of array). Ex. var numbers= ['1','2','3','4']; console.log(numbers.slice(2,3)); #=> array ["1","4"]

  • What did you Google to help you with this task, and how did you pick your results? I googled JavaScript array slice example to clarify the provided example and again chose trusted sources to sift through information.

  • In your own words, what does the JavaScript object values method do? As you're explaining, be sure to provide an example. Your answer: JavaScript object values create a set of data with a functon, which can be run without modifying the original set of data. Ex. const object1 ={ a=90 b='dancing' c=false }; console.log(object.values(object1)); #=>array [90,"dancing",false]

  • What did you Google to help you with this task, and how did you pick your results? Here I googled what are JavaScript object values. This was the most unclear of all the results I found.

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: Characters: Colonel Mustard, Mrs. Peacock, Professor Plum, Mrs. White, Ms. Scarlet, Mr. Green.
  2. Integer and/or float data: Roll of the dice: 1-6
  3. Boolean data: Accusation: Did Mr. Colonel do the murder? YES Was it with the wrench? YES Was it in the Billiard room? YES
  4. Array data: Game variables Characters: 6 Weapons: 6 Rooms: 9
  5. Hash or Object data: Possible combinations to result in the correct three options. Characters (6)----->(1) Weapons (6)----->(1) Rooms (9)----->(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.

  • Reciclying: Grab empty box, break down the box, place in reciclying bin, repeat until there are no more boxes. This is an example of iteration because there are multiple steps that are required to repeat until a specific condition is met (all boxes recycled).

  • Decorating: Grab decoraton, find location for decoration, use tack to hang decoration, repeat until there are no more decorations. This is an example of iteration as there are 3 sets of instructions that need repeating until a specific condition is met (no more decorations)

  • Note taking: Write inital set of notes, highlight or define as necessary ,transcribe notes to clarify info, repeat until there aren't any more notes. Again, there are a certain number of steps (3) that require repeating until the end contition is met (no more notes).

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

  • Password entry: Enter password, if not correct password repeat step 1, continue repetition until correct password is entered. This is a slightly different example of iteration as the last few. Here there isn't an end goal or number of times required to finish, but the requirement is the correct entry. It still has all the key components: a set of instructions to repeat (inital pw entry) until a specified condition is met (correct pw).

  • Course search: enter student name, class ID, if there is an open slot in a class enroll in course, if not repeat search. This would be used at a college or some kind of school to enroll in classes. Often times classes very in the number of slots open. This iteration would require criteria in order to add the class and would only end if there is an open slot in the course.

-Video advertisment: enter site, play video, repeat unless user hits button on keyboard. Here there is only one step that is being repeated (video playing) the user has to enter the site, but once they are there the iteration begins until the criteria of hitting a button is met.

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, @N-Gibson! For your iteration examples, all of your real-life examples are great with clear collections of what is being iterated over. For your programming examples, it seems they are more examples of recursion or looping where the loop continues until a condition is met. For it to be iteration, the end condition must be "all of the items have been gone over". You could change your course search example to be iteration by making the collection a list of courses to enroll in. Then for each course, enter the course number, enroll in that course, go to the next course. Hope that makes sense!

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