Skip to content

Instantly share code, notes, and snippets.

@Loomus
Forked from rwarbelow/mod_0_session_2_practice_tasks.md
Last active February 22, 2019 01:22
Show Gist options
  • Select an option

  • Save Loomus/3a965e6ce5608c84d70786b35e4176b7 to your computer and use it in GitHub Desktop.

Select an option

Save Loomus/3a965e6ce5608c84d70786b35e4176b7 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 method is used to drop a certain number of elements, that you choose, in an array and return what is left. For example, if there are 6 random integers in an array and the drop value is 3, than the first 3 integers will be removed while the last 3 will remain.

  • What did you Google to help you with this task, and how did you pick your results? I googled 'explain ruby drop array method' and looked at multiple sites to find almost the exact same explanation and example.

  • In your own words, what does the Ruby array push method do? As you're explaining, be sure to provide an example. Your answer: A push puts an object at the end of an exsisting array so that appends may be chained together. For example, if there is an array with 3 elements a push can be used to add to the end of the exsisting array.

  • What did you Google to help you with this task, and how did you pick your results? Googled, "What is a push in Ruby". Found mulitple examples and choose a link that gave a tutorial.

  • In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer: A split is used to cut up a string which will return as an array of substrings. For example, "He ran away".split #=>["He","ran", "away"]

  • What did you Google to help you with this task, and how did you pick your results? Googled, "What is a split Ruby". Found defintions for delimiter, split, and regex. Choose a code-maven.com link and a stackoverflow.com because they're sites with programming pedigree.

  • In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer: The slice method is used to take a portion of an array and make it a new object without changing the exsisting array. For example, var meats = ('beef', 'pork', 'poultry', 'fish') console.log(meats.slice(2)); // expected output: Array ["poultry", "fish"]

  • What did you Google to help you with this task, and how did you pick your results? Googled "What is a slice in Javascript". Found multiple defintions and choose a website w3schools.com to find another defintion based on a previous search.

  • In your own words, what does the JavaScript object values method do? As you're explaining, be sure to provide an example. Your answer: The object values method is used to return an array of the objects own enumerable property values and in the order given. For example, Input : var check = ['x', 'y', 'z']; console.log(Object.values(check)); Output : Array ["x", "y", "z"]

  • What did you Google to help you with this task, and how did you pick your results? Googled, "What is a object value in Javascript". Choose the first link with the definiton as it was similar to the hyperlink provided with the question.

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

  • 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: "Chess pieces" "Chess Board"
  2. Integer and/or float data: "32" "1"
  3. Boolean data: If 32 pieces and 1 board are present then play. True and True = True True and False = False False and True = False False and False = False
  4. Array data:['Pawn', 'Rook', 'Knight', 'Bishop', 'King', 'Queen'] [8, 2, 2, 2, 1, 1]
  5. Hash or Object data: {"WhitePawn" : 8, "WhiteRook" : 2, "WhiteKnight" : 2, "WhiteBishop" : 2, "WhiteKing" : 1, "WhiteQueen" : 1} - {"BlackPawn" : 8, "BlackRook" : 2, "BlackKnight" : 2, "BlackBishop" : 2, "BlackKing" : 1, "BlackQueen" : 1}

3. Iteration (30 min)

  • On a blank sheet of paper, create a diagram that shows how you understand iteration working. Be detailed and get creative! When you're done, take a photo of your diagram and post it in the Mod 0 channel on Slack. Your instructor(s) will provide feedback in a thread. (If you're feeling extra fancy, feel free to create your diagram using software instead of pencil and paper)

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

  • Washing Dishes- Soak dish in Hot-soapy water, scrub, rinse, dry, repeat till all dishes are washed.

  • Laundry- Sort clothes, Wash cycle, Dry cycle, Fold and put away, repeat til laundry is complete.

  • Reading a book- Start book, read a page, repeat until book is finished.

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

  • Converting Body Weight and Height to metric for each person in a class - Multiply the weight in pounds by 0.45 (the metric conversion factor) Multiply the height in inches by 0.025 (the metric conversion factor), repeat for next person.

  • Calculate Body Mass Index for each person in a class - Convert body weight and height to metric, square the answer for height, divide the metric weight by the squared height for BMI%, repeat for next person.

  • Calculate daily water intake for each person in a class - For person take weight in pounds and divide by 2.2, Multiply by age number, divide that sum by 28.3, the result will by the amount of water that person should drink in ounces daily, repeat for next person.

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! I like your logical operators real life example here: True and True = True.

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