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:
-
This method will remove a variable number of the first sequential elements from an array and then will print the array with the reamining elements. So say your array is named nums and it contains [2, 2, 0, 5, 7]. You will call upon the method like so: nums = [2, 2, 0, 5, 7] nums.drop(2) <---The number between quotes shows the elements in the first two spots will be dropped and it should print: #=>[0, 5, 7]
-
What did you Google to help you with this task, and how did you pick your results?
-
I looked at how the method was formatted on the Ruby dopcumentation and decided to search "drop(n) array ruby" knowing that including the variable might return results with examples. I chose hits from stack overflow and APIdock due to the examples that they showed and after a few, was able to get a good grasp on how it was used.
-
In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer:
-
It basically takes an entered string and can break it up into an array of smaller strings, based on what delimiter you choose. It can be every character or the blocks of characters between spaces. This method is useful for things like a search engine searching individual terms within and entered phrase. It may recieve the whole search the user enters as a single string but this method can break it up so that each word may be serached on its own.
-
What did you Google to help you with this task, and how did you pick your results?
-
I googled "Ruby string split method" and chose results that seemed to be related to tutorial type websites as I knew just understanding the method was probably not an overly advanced concept so a full Stack Overflow thread was probably not necessary. Many of the pages I opened had explanations on why it was useful and the different ways to delimit the string.
-
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, essentially will chop off an end or ends of an array at a specified star and/or end point. If you were to specify the 2 index, it would remove the items in the 0 and 1 index spots. The difference in the end point is that it is included in the slice. This means if you designated a slice with no start point but a slice end at 5, it would return the array from indeces of 0, 1, 2, 3, 4 but the 5 would be removed and anything that might be after it in that array. And of course, you can specify both a start and end point but the previous rules will hold true.
-
What did you Google to help you with this task, and how did you pick your results?
-
I first searched "JavaScript array slice method MDN" to take a look at the documentation since there seems to be good basic explanations there. Having a basic understanding, I just searched "JavaScript array slice method" and found a couple articles at length explaning how the method worked, with one being in Mozilla's web docs and containing a pratice IDE inser that showed how it would run.
Imagine that you're taking your favorite board game and turning it into a computer-based game.
-
Name of board game: Monopoly
-
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:
- Character pieces (ie shoe, dog, hat)
- Street names (Boardwalk, Baltic Ave, etc)
- Integer and/or float data:
- Amount of money each player has
- How much a space costs to buy
- How much is charged for landing on an owned space
- Boolean data:
- If you pass go, collect $200.
- If you land on a spot and someone owns it, pay X amount.
- If you land on a chance spot, draw a card.
- Array data:
- Names of all the spaces
- Effects of chance cards
- Hash or Object data:
- Player name
- Chosen game piece
- Turn in the rotation
-
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.
-
A graphic design team is hired to do a print campaign with a clothes company. Every week they draft up materials and meet with the client. Every time, the client gives feedback about what they like and what they want changed. They repeat this every week until the client is pleased with the overall design and then it is rolled out. It's an example of iteration because the graphic design team is doing the same process on a weekly basis and checking in with the client. They repeat this process until the condition of the client being pleased is met.
-
Video game designers use iteration when they create a build of their game and then have QA testers play it. They have them play, collect feedback on things like playability, character design, level design, and any bugs and then they make an update to the game. They will keep doing this until the acheive a version of the game that is stable and reviews well with testers in terms of fun and cool design. This is iteration because the game is being improved upon in each update until it meets the condition of being good enough to publish.
-
This one may be a stretch but an example coould be trilogies or long film series. They put out a new movie, pushing the story along and getting closer to the resolution of the issue at hand. They keep putting these movies out to fill the story and it completes at the end of the story's resolution. This could be seen as iteration because it is putting out a new film and progressing the story. If the story is not concluded yet, another movie must be put out until the story is resolved.
-
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.
-
A hacking program could be used to brute force a WiFi password. It could try every combination of all 26 letters and 10 numbers until it hits one that allows it to connect to that WiFi connection. This is iteration because each loop will try a new combo of characters and keep doing so until it gains access.
-
A really dumb script could be written for Windows could be written so that if you pressed the shift key 5 times it would activate "sticky keys". It would react normally to the shift key being pressed until the fifth input and could then activate the sticky keys program. This is iteration because each press of the key represents an iteration until the 5 condition is met and it turn the program on
-
You could code a program that would check the temperature reading on an external thermometer every day. If the temperature read below 70 degrees, it would do nothing and check again the next day at the same time. If it read the temperature above 70 degrees, it could send a signal to the AC unit to turn on. This is iteration because it checks a condition every day and keeps checking until the temperature condition is met and then turns on the AC unit.
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 the second one has student in () brackets rather than 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 the "sans-serif" font family doesn't have a - between the two words which wouldn't be recognized. |
| 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 the part in the second one where it reads (min(score) over ()) it should say (max(score) over ()) |
| 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 in the part in the original where it reads { |a,b| a == b }, the second one has 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 there is a typo in the word initialize in the second one where it reads "intialize" |
- 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:
Overall, nice work.
For the iteration situations, always start with a collection of something. For example, in Monopoly, you could have a collection of players. The iteration could be for each player, allow them a turn, then repeat for the next player in the collection.