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 drop removes or skips a predetermined number of elements in an array, specifically the first ones listed in the array.
For example, if we have the following array of fruits: [apples, oranges, pineapple, kiwi, pear]
Drop(2) would skip the first two elements in the array to produce this list: [pineapple, kiwi, pear]
- What did you Google to help you with this task, and how did you pick your results?
I googled "ruby drop method explanation" and in the search result summaries, I looked for an answer that made the most sense to me, specifically an answer that a beginning learner could understand. The first search result had that! SOURCE: http://www.rubycuts.com/developer-resources/ruby-enumerable-module/drop-method/
- In your own words, what does the Ruby array push method do? As you're explaining, be sure to provide an example. Your answer:
Push adds items to the end of an array. For example, if I had a list of dog breeds: [golden retriever, dalmatian, beagle, german shepard]. Using push(St. Bernard) would add St. Bernard to the end of the list: [golden retriever, dalmatian, beagle, german shepard, St. Bernard].
- What did you Google to help you with this task, and how did you pick your results?
I googled: ruby push method explanation. Again, I looked for an summary in the search result that I could understand. SOURCE: https://ruby-doc.org/core-2.2.0/Array.html
NOTE: For these searches, I am not worried about the date of the articles. Definitions like these likely do not change over time.
- 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 separates the content of a single string into multiple strings. For example, if I split the string "Jon Snow, Daenerys Targaryen, and Tyrion Lannister", then it produces: "Jon Snow" "Daenerys Targaryen" "Tyrion Lannister"
- What did you Google to help you with this task, and how did you pick your results?
I just modified the same google search that I did before. I searched: ruby split method explanation. I include the word explanation in my searches becuse I feel that this will help generate more websites that will have content that I can understand, perhaps geared more towards beginners in the field. SOURCE: https://www.thoughtco.com/using-the-split-method-2907756
- In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer:
Slice picks a specific element in an array. It specifically extracts that element and creates its own array for the selected element, but it does not change the original array. For example, if I had an array of [chocolate chip, sugar, peanut butter, white chocolate macadamia nut, m&m], then using splice(2) would result in [peanut butter]. (array elements start at 0, so a 2 would result in peanut butter, not sugar).
- What did you Google to help you with this task, and how did you pick your results?
I googled: javascript slice method explanation. Again, I was looking for results that I could understand from a beginner point of view.
SOURCE: https://www.tutorialspoint.com/javascript/array_slice.htm
- In your own words, what does the JavaScript object values method do? As you're explaining, be sure to provide an example. Your answer:
Object.values in Javascript will take everything listed under an object and create an array out of it. For example, if our object is this and has these values:
Cookie -sugar -flour -butter
then the values method will create an array of the values of the object cookie, which generates: [sugar, flour, butter]
- What did you Google to help you with this task, and how did you pick your results?
This one was admittedly confusing for me. At first, I thought that we had to define value, which is a whole other thing in Javascript. Googling: "object values definition" was not helping me, but the search "object.values javascript" came up with what I needed. In the future, I will be more specific in my searches and may even include some code in the searches to get a more specific answer
SOURCE: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values
Imagine that you're taking your favorite board game and turning it into a computer-based game.
-
Name of board game: Codenames
-
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: codename words "water, bottle, ship". Spy types "red agent, blue agent, double agent"
- Integer and/or float data: Integers: Number of codenames that you want someone to guess, like "1, 2, 3". Float: Number of seconds that someone has to guess a name: "35.62"
- Boolean data: If parter guesses correct code name, then we get to uncover our agent. If partner guesses an incorrect code name, then an innocent civilian is harrassed.
- Array data: List of codenames that a spymaster could make his partner guess easily [Berlin, Dublin, London]. List of characters on the board: [red agents, blue agents, double agent, civilians, assassin].
- Hash or Object data: {"Team 1": "Josh and Mikey", "Team 2": "Karen and Jeff"} {"Red agent codenames": "blue, coffee, plane", "Blue agent codenames": "light, window, table"}
-
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.
-
For making cupcakes: we put a cupcake liner in each mold in a pan, fill it with batter, then do the same thing to the other molds. This is an example of iteration since we are repeating the same task for each mold in the pan. (repeating same task for an object in collection)
-
For each dirty dish: I rinse it off and then put it in the dishwasher. I repeat with each dish. This is an example of iteration because we do the same task for each dirty dish, until there are no dirty dishes left. (repeating same task for an object in collection)
-
For mailing off envelopes: I put a stamp on each envelope, then put a return address on each envelope, and then put a mailing address on each envelope. This is iteration because I am repeating the same tasks for each envelope (repeating same task for an object in collection)
-
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 we have a list of the number of stocked items for cookie ingredients in an array, we may want to find out what the double of each number is if we need to order twice as many of the stocked items for a double batch of cookies. For example, if we have a list of bags of flour, sugar, and chocolate chips (ruby example: stocked items in order = [20, 3, 12]), doubling them would result in [40, 6, 24]. This is iteration because we are completing the same task on each object. In this case: doubling each stocked item count.
-
If we have a list of students (ruby example: names = ["steve", "laurel", "david", "ray", "leo"]), we may want to capitalize each one of the names if the names were received without capitalization. Capitalizing each name would result in: names = ["Steve", "Laurel", "David", "Ray", "Leo"]). This is iteration because we are completing the same task on each object. In this case: capitalizing each name
-
If we have a list of meeting times (ruby example: meeting_times = [7:15, 12:00, 14:30]), and I am running late today and I need to reschedule them a bit later to accomodate my schedule, then we may want to add one hour to each meeting time to move back my schedule, resulting in meeting_times = [8:15, 13:00, 15:30]. This is iteration because we are completing the same task on each subject. In this case: adding one hour to each time.
- 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:
Good job, @joshsherwood! Great examples of iteration.