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.
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: my_array.drop(n) will return the last n elements of my_array
-
What did you Google to help you with this task, and how did you pick your results? I first googled ruby documentation and then once at ruby-doc.org I searched drop and then could find details of the method there on the array page
-
In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer: my_string.split(my_delimiter) will return an array of substrings of my_string using my_delimiter as the criteria for what to split the string on
-
What did you Google to help you with this task, and how did you pick your results? I didn't need to google for this as I was already on ruby-doc.org so I navigated to the string object and then could find the split method there
-
In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer: non-destructively this will return a copy of an array myArray using either one parameter to represent from which index to return the elements or two parameters to return a range of elements from the array, e.g. myArray.slice(3) will return all elements after the 3rd element of myArray, myArray.slice(3,5) will return elements 4, 5, and 6, in other words elements with indices 3, 4, and 5
-
What did you Google to help you with this task, and how did you pick your results? I went directly to the Mozilla documentation in the link above, I googled js variable declaration as I wanted to double check that js variables are declared using camelCase, e.g myArray, instead of using underscores which I read is best practice in Ruby, e.g. my_array
Imagine that you're taking your favorite board game and turning it into a computer-based game.
-
Name of board game: Scrabble
-
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.
- String data: player1 = "Dave", player2 = "Frank" ... , player_turn_now = player2
- Integer and/or float data: number_of_players = 2, total_turns_taken = 11
- Boolean data: board_tile_free = true/false, current_word_permitted = true/false
- Array data: players = [player1, player2], words_on_board = [word1, word2, ...], permitted_words = [aword, bword, ...]
- Hash or Object data: points per letter of alphabet, e.g letter_points = { a => 1, b => 3, c => 2, ... } player_scores = { player1 => 23, player2 => 17, ... }
-
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.
-
Packing a suitcase:
clothing item needs to taken from clothing item collection and packed into suitcase
repeated until suitcase is full or until number of items packed = number of items in clothing collection
Is iteration as it is a repetitive task that gets repeated until a criteria is met -
Cutting someone's hair:
for each bunch of hair
cut bunch from hair collection do until client is happy
Also a repetitive task as the exercise of cutting the hair gets repeated until the person who's hair is being cut is satisfied. -
Swim 40 lengths: for number of lengths = 1 to 40
swim length
number_of_lengths += 1
next length
Also a task that gets repeated, ie swimming each length, however the number of times the task is repeated is defined at the beginning, taking care to avoid an infinite loop, ie swim until the pool is empty -
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.
-
programming an elevator:
for each floor in collection of floors
if floor = floor requested then
stop
open doors
exit
else
move floor
end
next floor
Is an iteration as there is the repetition of a task until a condition is met -
user trying to register on website:
check database to see that not already registered
for each user in collection of users in user table
if new user = user then
puts "you are already registered"
user_registered = true
end
next user
if not user_registered then
add_user
message = "welcome you have been registered successfully"
end
An example of iteration as each user already in the db needs to be checked against the new user and repeated until all existing users have been iterated over -
Send email to all students of mod 0 6B
for each student in students
if pre_work(student) = mod6b then
send_email(student)
end
next student
Another example of iteration that performs a repetitive task, could be done manually one by one for each student but thanks to programming can be run in a few seconds!
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... use of round braces instead of curly braces |
| .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... omitting the hyphen in sans-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... use of 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... use of b == b instead of a == 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... misspelling of initialize |
- 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\`$ "
If you have any questions, comments, or confusions from the any of the readings that you would an instructor to address, list them below: