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: A Ruby array drop method seems to let you drop the first instance of a variable, and return the later elements of the array as a new array. So If you have an array like this: x = [100, 100, 100, nil, 100, 100] and drop the nil (presumably through a.drop = (nil)) the return would be a new array of [100, 100]
-
What did you Google to help you with this task, and how did you pick your results?
-
I first started by following the link in the question, which seems to have taken me to some official documentation. I could understand what was happening here, but coming up with my own example would require some deeper understanding. I googled "drop elements from arrays ruby" and found a blog that had a much more detailed decription. I checked a few more sources, using command + f to find "drop" on the page, and they all seemed to be in agreement. While I'm not 100% sure my example is functional, I feel like I understand the use of the drop method better than before.
-
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 string "split" method seems to take a string, and split it up into different parts, returning them in an array. If your user enters their address as "123 South Street, Apartment #1" you could collect that, and enter it with .split at the end, and ruby would return the seperate elements as an array: ["123", "South", "Street,", "Apartment", "#1"]
-
What did you Google to help you with this task, and how did you pick your results?
-
In this search, I found the official documentation to be helpful enough. Funnily, the explanation was more difficult than just looking at the code snippets themselves. I found that helpful for noticing that when the string gets split, they don't return just as an array, but more specifically as an array of substrings, each in their own quotation marks. I googled "split string ruby" and compared what I found, just to be sure, but I felt pretty confindent in the official source.
-
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 in javascript copies selected parts of an array and returns them as a new array, leaving the original array untouched. It operates by telling Javasrtipt to slice the array FROM a designated element, UNTIL a designated element. So if you have an array of [1, 2, 3, 4, 5, 6], and you wanted to copy the first 4 integers into a new array, you would type array.slice(0,4); because the array starts count at 0 (I believe?), and then would copy until the 4th integer, leaving you with [1, 2, 3, 4]. If you wanted to slice everything after 3, and before 6, you would type array.slice(3,5).
-
What did you Google to help you with this task, and how did you pick your results?
-
I initially used the documentation provided in the link inside of the question, but I could not understand the logic of how the numbers of the elements correlated with the output array, because I wasn't accounting for starting at 0, and I needed to understand how it was still returning the 5th element, when the slice was something like (1,5). I turned to a blog post on medium after searching javascript slice explained. The narrative style of the blog post was very helpful in clearing this up for me.
Imagine that you're taking your favorite board game and turning it into a computer-based game.
-
Name of board game: Clue
-
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: "Miss Scarlet", "Professor Plum", "Candlestick", "Wrench", "Kitchen", "Study", etc
- Integer and/or float data: Dice rolls for character moves 1,2,3,4,5,6 etc
- Boolean data: True or false statements on suggestions of who killed who, where, with what. Miss Scarlet with the Noose in the Library could come back after evaluating those statements: false, false, true. All statements could have to evaluate to true in order to return confirmation of the suggestion.
- Array data: Character names: ["Miss Scarlet", "Colonel Mustard",] etc. Could also be weapons, rooms, or even the correct answer in its own array of ["character name", "room name", "weapon name"]
- Hash or Object data: This could be values assigned to each of the string categories, such as assigning each character, weapon, and location to it's own value, to speed up indexing. {"Colonel Mustard":1}, {"Miss Scarlet":2}, etc
- 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.
- Editing Photos. It's an example of iteration, because there is a collection (Photos) and a collection of tasks to perform for each photo in the collection. Those tasks could include many things, such as opening the photo, editing contrast, applying filters, cropping, saving, renaming to a standard format, etc. The loop would continue until all photos have been edited.
- Sorting art supplies. I have a large collection of paint markers in a carrying case, but they get mixed up to the point that I can't find the one I want without hunting for a while. For each marker, I would pick up the marker, evaluate it on the RGB scale, place it in its spot on the RGB spectrum, and move on to the next marker.
- Logo design. I'd first have to come up with a large collection of thumbnail sketches (lets say 50), but then I could start a loop to evaluate them. I'd select each thumbnail, one by one, and run them through some critique based on 1)how they mesh with client needs, 2)their strength as relates to the principles of design. Then I repeat the process to narrow down the collection to a group of my top 10. Even after that, there would be another loop of critique on the top 10 to bring it down to top 3 or so, at which point we would get feedback from the client, starting another loop of critique based on that feedback.
- 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.
- If I created an app to batch-edit photos, that process I described above could become an actual example of iteration in programming. The user could select some presets, or even edit the first photo manually. Then the loop could be initiated, telling the program to select the next photograph, apply the user-selected edits, save the photo with the desired naming structure, move on to the next photo and repeat until all photos were edited. Scennario: Batch-Editing Photos. Collection: Photos. For each:Photo Do This: Apply User selected edits. Then: Repeat with next photo
- If I wanted to create an app to alert me to to various significant meteor showers in my area, I would feed the current calendar date and my location to the app, and create a loop that would select each calendar day, compare it to a database of important meteor shower dates for my location and return a notification to the user if the curent date matched with any significant dates in the database, it would repeat every day, only returning true if a match was found, and sending the notification. Scennario: Alert for Meteor Showers in your Area. Collection: Calendar dates. For each:date Do This: check against database and location Then: repeat for next date.
- I could create a web platform for selling prints of my artwork. I could create a database with the number of prints in stock, and program it to check after every sale, looping until stock reached a value I considered to be low. At that point it could send an email to my mailing list, alerting them of the low stock, hopefully encouraging them to make a purchase. Scennario: Low Stock Alert. Collection:Prints For each: Print Do This:check stock until stock = low Then: Alert mailing list of last chance to purchase. Repeat with next print.
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 that it should be "Welcome, #{student}" with the curly braces instead of parentheses. |
| .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 that it is missing the hyphen in between the 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 that it has min(score) instead of max(score) on the second line. |
| 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 within the first curly brace. a==b in the original, b==b in the second column. |
| 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 spelled incorrectly in the mistake column. It is missing the 2nd "i" |
- 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: