Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Garrett-Iannuzzi/7e536230beecce3e60fed24a12d9c08c to your computer and use it in GitHub Desktop.

Select an option

Save Garrett-Iannuzzi/7e536230beecce3e60fed24a12d9c08c 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: Removes the elemnents in an array from the chosen element location as well as the elements before it Ex: if you have elements 1,2,3,4,5,0 and you select a.drop(3) you will lose 1,2, and 3.

  • What did you Google to help you with this task, and how did you pick your results? "ruby array drop method" I used a stackoverflow cross referenced with the link above to form my answer.

  • In your own words, what does the Ruby array push method do? As you're explaining, be sure to provide an example. Your answer: Makes sure that the selected elements are pushed to the end of the array Ex: Elements a,b,c,d,e,f and you a.push(a,b,c) your new order will be d,e,f,a,b,c

  • What did you Google to help you with this task, and how did you pick your results? "ruby array push method" I used a blog post crossed with the link above to form my answer.

  • In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer: Makes substrings out of strings and returns them in an array. Ex: If you wanted to split a sentence into words v letters.

  • What did you Google to help you with this task, and how did you pick your results? "ruby string method defined" I actaully had some trouble finding a straight deffinition for this question so I used only the link provided and the answer that google populated.

  • In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer: Makes copies of the array without chainging the original, starting at the satrt and ending with but not including the end of the array. Ex: You have a list of favorite foods: pizza, pasta, bugers, veggies. You want to make a copy of the array without pizza and pasta so you would (foods.slice(2)); so your array would be expected output: Array: ["burger","veggies",] I'm not 100% here...

  • What did you Google to help you with this task, and how did you pick your results? "javascript array slice method" I used a w3schools page crossed with the provided link.

  • In your own words, what does the JavaScript object values method do? As you're explaining, be sure to provide an example. Your answer: Using this method returns an array that is the same as the given object. The objects can't be numbered in this case. Ex: An array that involves a word, a number, and true v false statment.

  • What did you Google to help you with this task, and how did you pick your results? "object values method javascript" I used googles deffinition combined with mozilla.

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

  • 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 1 name", "player 2 name", "player 3 name", "player 4 name"]
  2. Integer and/or float data: Number of spaces you can move, 1-12.
  3. Boolean data: You either won or lost.
  4. Array data: each card and its outcome, ex: card 1= move one space
  5. Hash or Object data: object=sorry card where you are moved back to start

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.

  • Cooking. You follow a list of ingredients until the meal is ready.

  • Cleaning. You pick up things and repeat until the house is clean.

  • Shipping. Items are placed on a belt and sent to locations until there are no more items to ship.

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

  • Ordering a list. You sort iteams of the list based on a set of variables until there are no mroe items to sort.

  • Figuring out combinations of things. Your program could be told to rearrange a series of letters until all of the different combinations have been made.

  • Programming in calcuations for banking. If you want to figure out how much you spent on going out. The loop looks for charges for food and bev and adds them until they are all gone.

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:

  1. Sometimes it's hard to move forward without knowing if my answers are right. I'm worried I will develop bad habits if I go on thinking I have something down but actually don't. Not sure if this makes sense but just looking for some advise on how to get passed this midset.
@katiescruggs
Copy link

katiescruggs commented Apr 9, 2019

Nice work, @Garrett-Iannuzzi! I understand that it might be hard to move forward without being sure that you're understand, but the most important thing at this stage of your learning is to gain an understanding of the core concepts like data types, iteration, and object oriented programming. For the other concepts, it is helpful to be exposed to them now so to make it easier to understand them when you learn about them again in Mod 1! Don't worry about gaining bad habits, because any bad habits you pick up will quickly be stopped when your code doesn't work (or when an instructor corrects you).

On the iteration examples, make sure you are thinking about collections of things to go over. Not exactly sure that the collection would be in the rearranging letters example, but all of your other examples look good.

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