Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save DerekBird/9fd3b51daacefd75ab19fa68426e7730 to your computer and use it in GitHub Desktop.

Select an option

Save DerekBird/9fd3b51daacefd75ab19fa68426e7730 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 array drop method removes the first number of specified elements from an array and returns the remaining elements. Example a = [17, 24, 38, 52, 73, 91] a.drop(2) [38, 52, 73, 91]

  • What did you Google to help you with this task, and how did you pick your results? I initially searched "Ruby array drop method" however this only brought up results from Turing mod 0. I then searched Ruby array method drop and had many more results.

  • 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 Ruby array push method places the specified elements to the end of an array. You may push several elements at the same time. Example a = ["apple", "banana", "peach"] a.push ("orange", "strawberry") ["apple", "banana", "peach", "orange", "strawberry"]

  • What did you Google to help you with this task, and how did you pick your results? I searched "Ruby arrar push method" This time I was given results outside of just Turing materials but it was difficult to determine the date the pages were published or they were older so I searched without quotations.

  • In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer: The Ruby arrey split method divides a string into different pieces in a way that the developer defines Example "It's raining out".split ["It's", "raining", "out"]

  • What did you Google to help you with this task, and how did you pick your results? I searched Ruby string method however the results I got were a bit too technical for me so I searched what does the Ruby string split method do and I was given more results and some in easier to understand terms

  • 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 JavaScript array slice method selects elements in an array specified by the developer and returns these elements in their own array. Example var beers = ['IPA', 'Lager', 'Pilsner', 'Kolsch', 'Stout'] console.log(beers.slice(3)); // expected output: Array ['Kolsch', 'Stout']

  • What did you Google to help you with this task, and how did you pick your results? I searched JavaScript array slice method. I began reading an article from W3Schools but remebered I had been warned about using them as a source so I went with an article from StackOverflow instead

  • In your own words, what does the JavaScript object values method do? As you're explaining, be sure to provide an example. Your answer:

  • What did you Google to help you with this task, and how did you pick your results?

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: [Sorry the game of sweet revenge] [For 2-4 players]
  2. Integer and/or float data: players = ['1', '2', '3', '4'] zones = ['1', '2', '3', '4', '5']
  3. Boolean data: If a player is in the safety zone they cannot be bumped: True If a player is not in the safety zone they cannot be bumped: False
  4. Array data: players = ['blue', 'green', 'red', 'yellow] zones = ['Start', 'Slide', 'Safety Zone', 'Home', 'Regular Space']
  5. Hash or Object data: ['Player 1' => 'blue', 'Player 2' => 'green', 'Player 3' => 'red', 'Player 4' => 'yellow']

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.

  • Taking attendance at the beginning of class and marking each student either present or absent

  • Making a shopping list and write whether you need an item or not if you already have it

  • A list of chores and marking which items have been completed and what still has to be done

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

  • You have a list of names and you want them all printed. This is iteration because you are using the print action for all the names listed.

  • You have a list of clothing item prices and you want to mark them 50% off. You would be making all clothing items 50% off.

  • You have a list of animals that are extinct and you need to mark them as such. You are adding the same attribute to all of the animals.

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. I am having trouble with JavaScript Object Values Method
@katiescruggs
Copy link

Nice job, @DerekBird! The JavaScript Object.value() method returns the values of an object.

const values = Object.values({ key1: "value1", key2: "value2", key3: "value3 });
// ["value1", "value2", "value3"]

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