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: The drop method removes the first 'x many' items in the array and leaves the rest. Ex. If an array has 1 - 10, the drop method for drop(2) would drop the first 2 items which would be 1 and 2.
-
What did you Google to help you with this task, and how did you pick your results? I Googled ruby array "drop method". I didn't understand the simple explanations that came up so I looked at the videos tab and found a short video that explained it clearly,
-
In your own words, what does the Ruby array push method do? As you're explaining, be sure to provide an example. Your answer: The push method adds (or pushes) additional listed objects onto the end of an array. Ex. ["one", "two", "three"].push("four").push("five")
-
What did you Google to help you with this task, and how did you pick your results? I Googles ruby array "push method". I picked an un-dated gistpages result which had "using ruby array push method" in the description. It linked me to the same rubydocs link as the question.
-
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 separates the objects in a string into separate strings. Ex. "Chris, Heather, Erica" applying the split string method will produce "Chris", "Heather", "Erica"
-
What did you Google to help you with this task, and how did you pick your results? I Googled Ruby array "string split method" and found a thoughtco.com article from March 2019 that explained it in writing and included code examples which helped me understand parts of the writing that I didn't understand.
-
In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer: JavaScript slice method extracts specific elements of an array. Ex. "Chris, Heather, Erica, Rachel, Becca" . slice(3) will extract element 3 and onward. "Rachel", "Becca"
-
What did you Google to help you with this task, and how did you pick your results? I Googled JavaScript array slice method and found a developer.mozilla.org link from April 2019.
-
In your own words, what does the JavaScript object values method do? As you're explaining, be sure to provide an example. Your answer: JavaScript object values method creates an array where the collection elements are made up of the object's values. (Objects are collection of Key-Value pairs so the values the make up the array created by the object values method are the 'values' assigned in the object.) Ex. var obj = { Chris: 35, Heather: 34, Erica: 30, Rachel: 28, Becca: 26 } console.log(Object.values(obj)); // [35, 34, 30, 28, 26 ]
-
What did you Google to help you with this task, and how did you pick your results? I Googled JavaScript Object Values Method and selected the developers.mozilla link.
Imagine that you're taking your favorite board game and turning it into a computer-based game.
-
Name of board game: Settlers of Catan
-
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: "resource card" "die" "trade"
- Integer and/or float data: Number of Victory Points, number rolled on the die, and number of roads would all be integers. Nothing in the game would have a decimal point to be a float.
- Boolean data: Does player X have longest road? Is my settlement/city touching the number rolled on the die? Do I have more than 7 cards when a 7 is rolled?
- Array data: [ "ore", "grain", "lumber", "brick", "wool" ] [ "road", "settlement", "city" ]
- Hash or Object data: { "1 brick, 1 lumber" : "road", "1 brick, 1 lumber, 1 wool, 1 grain" : "settlement", "3 ore and 2 grain" : "city" } { "city" : 2, "settlement" : 1, "road" : 0 }
-
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.
-
List of arriving reservations. If rate plan includes breakfast > Open reservation, add comment, save and close reservation. Repeat until done for all reservations with rate plans including breakfast. This is iteration because it takes a collection, pulls items from that collection and repeats the same set of steps on them until there are no more items to do it on.
-
Requests off for next pay period. Evaluate demand for the specific date requested off, action the request as approve/deny, update the schedule, repeat for all requests. This is iteration because it goes through a collection of request offs, takes action(s) and stops when the list is complete.
-
Recipe ingredient list. For each item > find at the store, add to cart, cross off list. Repeat until end of list. This is iteration because it actions the same steps for a collection of items, one by one.
-
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 of student names entered by users on a teaching resource website > take each name and change the format so that the first letter only is capitalized, repeat with next name through the whole list. This is iteration because an action is taken to each item in the collection.
-
Website for a brewery tour. When each user enters their birthdate to get into the website, the iteration would be the system subtracting the entered date from today's date, then using a boolean to only allow access if the results is greater than or equal to 20. This iteration does the math on each user entry then allows or prohibits access based on the result. **Would this still be considered an iteration if its one piece of data at a time rather than a collection that is already altogether?
-
Students enter their answers into an online tool during class > each answer is checked for correctness/match then displays either a green star or red slash until the first three correct answers are completed. This is iteration because the action is done to each item until 3 are done.
- 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:
- I have a question that popped up when thinking of programming examples of iteration. If a website has users enter data then takes action on it, is it considered an iteration? Since the data is only being entered when someone tries to access the website, is it still considered part of an array/collection?
Nice job, @hfaerber! Good question -- if a program is waiting for user input, that is not iteration because there is no collection/array being looped over. Instead, the website is probably just listening for an event. So your programming iteration example #2 is not really iteration, but if you had all of the user inputted birthdays in an array and then looped over them, that would be iteration.