Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RayRedGoose/b254d8c8408eee424d3681b9bf03ff5c to your computer and use it in GitHub Desktop.
Save RayRedGoose/b254d8c8408eee424d3681b9bf03ff5c 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:

    It removes adjusted number of elements from at the beginning of an array and create new array containing the rest of elements instead of previous. An example: we have array: grocery = ['milk', 'eggs', 'beef', 'ice cream', 'juice'] and we want to delete first two items from array. this command will be looks like: grocery.drop(2) and we'll get new array starting from the third element 'beef': grocery = ['beef', 'ice cream', 'juice']

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

    I entered the question and selected several results from top. I read an information there and found 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:

    String split method divides a string into elements based on a delimiter, returning an array of these parts. The delimiter itself can be a string or regular expression. An example: we have string: "Mother, Father, Daughter, Son" and we want to to split a string every place where there is a comma. this command will be looks like: "Mother, Father, Daughter, Son".split(', ') and we'll get new array: a = ['Mother', 'Father', 'Daughter', 'Son']

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

    I entered the question and selected several results from top. I read an information there and found answer.

  • 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 array slice method selects the elements starting at the given start argument, and ends at, but does not include, the given end argument. Sliced elements will be returned as a new array. An example: we have array: animals = ['Deer', 'Dog', 'Horse', 'Owl', 'Goose', 'Elephant'] and we want to choose birds from it. this command will be looks like: var animals = ['Deer', 'Dog', 'Horse', 'Owl', 'Goose', 'Elephant']; var birds = animals.slice(3, 4); console.log(birds); and var birds will be showed as: "Owl, Goose"

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

    I entered the question and selected several results from top. I read an information there and found answer.

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: names of pieces ('King', 'Queen'); name of a game position ('Checkmate', 'Stalemate');
  2. Integer and/or float data: 13 (number of moves, integer), 10,5 (seconds, time of a move, float);
  3. Boolean data: Can King do other moves? yes (true) or no (false); Can the white Queen at a3 capture the black Pawn at e6 in this move? No (False);
  4. Array data: pieces = ['king', 'queen', 'rooks', 'bishops', 'knights', 'pawns']; colors = ['white', 'black'];
  5. Hash or Object data: numbers of pieces: {"pawns": 8, "knights": 2, "bishops": 2}; positions: {"white king": "d1"; "black queen": "d8"};

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.

  • making salad: for each vegetables do this 1. take vegetable 2. wash vegetable using water 3. put it on cutting board 4. take a knife in hand 5. cut the vegetable into small pieces 6. put the pieces in a salad bowl 7. the repeat the 1st step. It's iteration because for each vegetable the same order of actions is repeated.

  • signing papers: for each paper do this: 1. take paper 2. sign 3. repeat the 1st step. It's iteration because for each paper the same order of actions is repeated.

  • drinking tea: for each sip do this 1. bring a cup to your mouth 2. do a sip 3. put a cup on the table 4. repeat the 1st step. It's iteration because for each sip the same order of actions is repeated.

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

  • list numbering: for each item do this 1. choose one string related to the item 2. assign next serial number to it 3. repeat the 1st step. It's iteration because for each item the same order of actions is repeated.

  • counting length of string: for each letter do this 1. choose letter 2. define number of previous letter 3. add 1 to this number 4. assign received number to chosen letter 5. repeat the 1st step. It's iteration because for each letter the same order of actions is repeated.

  • checking for errors: for each word do this 1. select word 2. check for error 3. mark word 4. repeat the 1st step. It's iteration because for each word the same order of actions is repeated.

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 Round brackets instead of Curly
.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 lost dash between sans and serif
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 min instead of max
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 b instead of a
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 lost i in word "initialize"

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. n/a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment