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 'n' elements from an array, and prints the remaining.
-
What did you Google to help you with this task, and how did you pick your results? How to Ruby Array drop method I clicked through the provided link, then clicked 2 other links and found that they both used the same example. From there, I looked through the examples to see whether I understood what was happening.
-
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 elements to the end of an array. Pushing three elements to the 'family' array would look like this: family = [ "mom", "dad"] family.push ("baby girl", "baby boy") #=> ["mom", "dad", "baby boy", "baby girl"]
-
What did you Google to help you with this task, and how did you pick your results? I googled how to push array ruby, and sorted through answers from multiple sites until I recognized the commonalites.
-
In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer: Strings contain blocks of data that can be seperated based on a delimiter. For example: value = "One Two Three" value.split(" ") this will remove the space between the string to that it prints as "One" "Two" "Three"
-
What did you Google to help you with this task, and how did you pick your results? I googled split string ruby, this brough up results explaining regex which I did not understand, so I filtered that from my results to specifically look for strings.
-
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 will create a new array that copies the first given value, up until but not including the last given value in the argument, such that you have a new array with some elements of the original. Ex: var scores = [ 27, 40, 32, 29, 19 ] var even scores = scores.slice(1, 3)
-
What did you Google to help you with this task, and how did you pick your results? I googled javascript array definition, then went through each sites explaining. Then found a site that allowed me to run their provided example.
-
In your own words, what does the JavaScript object values method do? As you're explaining, be sure to provide an example. Your answer: The Object.value takes an array as an argument, and displays the value of each property within that array. For example (in pseudocode): const djavan { height: 6 feet weight: 250 lbs hair: curly } djavan.value = 6 feet, 250 lbs, curly
-
What did you Google to help you with this task, and how did you pick your results? I googled the definition of object.value, and found some blog posts explaining properties, and why we would want to grab their values using this method.
Imagine that you're taking your favorite board game and turning it into a computer-based game.
-
Name of board game: Battleship
-
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: Player 1, Player 2
- Integer and/or float data: The spaces on the board
- Boolean data: Hit / Not hit when guessing
- Array data: The board, the ships
- Hash or Object data: The battleships occupied space
-
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.
-
Checking out at a supermarket. You grab each item, scan it, place it in a bag, then search for each item until complete. Each item needs to be scanned, until I am able to pay and check out.
-
Getting dressed: Grabbing each article of clothing, placing it on your body, until fully clothed. Each item of clothing needs to be added to my body before I can consider myself fully dressed.
-
Making Cereal. Each ingredient must be added to a bowl in succession before I am able to eat the food in the bowl.
-
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.
-
Calculating discounts based on whether an item is on sale. If Item x contains 'on sale' property, apply % discount. This could be used when iteration over each new item in a shopping cart.
-
Determining whether a player is shot in a video game. If projectile x meets path of player y, apply n damage to player y's health bar.
-
Determining whether Siri should search for an answer on the internet. If users "Hey Siri" = true, perform search function. If False, do nothing.
- 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:
- Should we be studying syntax when completeing these assignments, or is using pseudocode good enough for answering these quetions?
Nice work, @djavanm! Using pseudocode is good enough for answering these questions. The point of this assignment is to practice googling technical questions and to understand the concepts of data types and iteration. Of course if you have extra time, it never hurts to start getting some reps in with syntax!
Most of your iteration examples look great! For the last two programming examples though, I don't think there is a clear collection that you are iterating over. Siri responds to your voice rather than looping over a set number of items, and a player is shot in a video game when the projectile hits. Keep collections in mind as you continue thinking about iteration.