Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mcat56/2a48794497462a1f3bdce21b62e605fd to your computer and use it in GitHub Desktop.
Save mcat56/2a48794497462a1f3bdce21b62e605fd 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 (60 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: drop takes parameter n for number of elements to remove from the beginning of an array and returns the array with those elements removed. ex: array.drop(4) -> removes first 4 items from array and returns remaining. drop_while can be used to iterate through and remove items from an array based on condition/block code.

  • What did you Google to help you with this task, and how did you pick your results? I googled ".drop ruby" and went to APIdock for general overview of method. Ruby-doc and stackoverflow would be my next go-to based on what I have been using for studying. API dock is also one that I have gone to so it is familiar to me.

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

    Split takes a string based on a delimiter, or where you want to split, for each word, each whitespace, each comma, etc. string = "I love to code" string.split("") -> ["I"," ", "l","o","v","e"," ","t","o"," ","c","o","d","e"] There is different .split syntax to do same thing, e.g. split(" ") == split You can split based on match to RegEx pattern Second parameter can be given as a limit to how many split substrings will be returned (captured groups returned but do not contribute to limit - what are captured groups?). A negative number - no limit. Limit of 1 - whole string returned. Trailing null fields suppressed? Not sure what this means.

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

Googled "ruby .split" - again used familiar sites. For the purpose of this exercise I stuck with APIdock- explains and gives examples. Hoping all info on APIdock is current?

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

java slice method returns part of an array based on two inputs for beginning and end, beginning being inclusive for start index and end being exclusive for end index.

array = [1,2,3,4,5] array.slice(2,4) -> [3,4]

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

I googled java array slice method - looked through different results, picked those that gave the best examples and descriptions. Remember that we should maybe stay away from w3schools - not current? MDN and javapoint.com were the ones I found that I liked best.

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

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

Categories : "Data Head", "Creative Cat", "Star Performer", "Word Worm"

  1. Integer and/or float data:

Number of Players: 4-6 // Spaces to Move: 1-4 // Number of Teams: 2-3

  1. Boolean data:

Winning or losing? true or false // Move forward? true or false

  1. Array data:

Winning cards ["challenge1","challenge2",challenge3"] // Player Names ["Sam","Kyle","Rebecca","Eric"]

  1. Hash or Object data:

Spaces moved per team { "team1" : 24, "team2" : 20}

Team 1 stats over multiple rounds { "wins" : 3, "losses" : 2}

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.

  • Car assembly/manufacture: each part passes through and is modified/built, when finished the same is repeated for the next part. This is an example of iteration because the process is repeated over many items in loop.

  • Register: For each customer take their order and receive payment. Iteration applies as it is a repeated procedure for each person.

  • Wrapping gifts: For each gift wrap item, move to next. This is an example of iteration because you do the same thing for each gift until you are done wrapping all of the gifts.

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

  • Taking an array of integers (speed of vehicle) and calculate for each speed time to travel X distance. This is iteration because you are repeating the same formula for each item in the array to output a result for each item.

  • For each user input for name (array of strings) return greeting; "Welcome to Turing #{name}". This again is repeating a procedure for every item in a collection and outputting a result for each.

  • For each listed house price in a collection calculate property tax. This iteration runs through each price, listed as an integer and uses the same formula to output a unique result for each item.

4. Identifying Mistakes (15 min)

The following code examples each contain a mistake. Describe the problem for each.

Original Mistakes Problem
students.each do |student|
  puts "Welcome, #{student}"
end
students.each do |student|
  puts "Welcome, #(student)"
end
The problem is...Student should have {} not ()
.main-content {
  font-size: 12px;
  border: 3px solid black;
  font-family: sans-serif;
}
.main-content {
  font-size: 12px;
  border: 3px solid black;
  font-family: sans serif;
}
The problem is...sans serif needs hypen!
log(2, (1022 * ((score - min(score) over ()) / ((max(score) over ()) - (min(score) over ()))) + 2)::numeric) log(2, (1022 * ((score - min(score) over ()) / ((min(score) over ()) - (min(score) over ()))) + 2)::numeric) The problem is...It should be max(score) in the first () set
arr.product(arr).reject { |a,b| a == b }.any? { |a,b| a + b == n } arr.product(arr).reject { |a,b| b == b }.any? { |a,b| a + b == n } The problem is...The conditional should be a==b not b==b
class Cat
  attr_reader :color, :name
  def initialize(data)
    @name = data[:name]
    @color = data[:color]
  end
end
class Cat
  attr_reader :color, :name
  def intialize(data)
    @name = data[:name]
    @color = data[:color]
  end
end
The problem is...Initialize is missing an i !

5. 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. Do we need to install Ruby/Ruby Rails or will we go through that together and do you recommend waiting to do so?
@damwhit
Copy link

damwhit commented Jul 3, 2019

@mcat56 nice work on this!

Also, I think we addressed the above question after session 3, but let me know if you have any follow up questions!

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