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 Ruby array drop method takes out a number of items from the beginning of an array. Drop takes an argument that determines the number of items to remove and returns the rest of the elements in the array.
favorite_fruits = ["pineapple", "mango", "watermellon", "peach", "plum"]
favorite_fruits.drop(2)
["watermellon", "peach", "plum"]
-
What did you Google to help you with this task, and how did you pick your results? I searched: 1. drop method ruby 2. what does the drop method do ruby 3. drop method vs shift method
I read over sevearl descriptions and and choose my results once I noticed there was consistancy in both the descriptions and the examples. -
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 Ruby array push method adds a value or vlaues to the end of an array and returns the new array.
favorite_fruits = ["watermellon", "peach", "plum"]
favorite_fruits.push("rambutan")
["watermellon", "peach", "plum", "rambutan"]
-
What did you Google to help you with this task, and how did you pick your results? I searched: 1. push array ruby 2. what is array.push in ruby
I choose my rusults in the same way I did in the previous question except I used more tabs this go around. -
In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer:
A string split in Ruby can cut or divide a string into pieces based on a deliminter returing an array of smaller strings.
my_string = "These are my favorite fruits."
my_array= my_string.split(" ")
["These", "are", "my", "favorite", "fruits."]
my_string = "These are my favorite fruits."
my_array= my_string.split("")
["T", "h", "e", "s", "e", " ", "a", "r", "e", " ", "m", "y", " ", "f", "a", "v", "o", "r", "i", "t", "e", " ", "f", "r", "u", "i", "t", "s", "."]
-
What did you Google to help you with this task, and how did you pick your results? I searched: 1. what is string split in Ruby 2. what does the split method do Ruby 3. split method examples Ruby
I choose my results carefully after cross referencing several sources. -
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 reterns the selected strings in an array as a new array. You can give the slice() method a start and end argument. The resulting new array does not include the end argument.
favoriteFruits = ["pineapple", "mango", "watermellon", "peach", "plum","rambutan"];
console.log(favoriteFruits.slice(3));
["peach", "plum", "rambutan"]
console.log(favoriteFruits.slice(1,4));
["mango", "watermellon", "peach"]
-
What did you Google to help you with this task, and how did you pick your results?
I searched: 1. what is the slice method in javascript 2. what is the "slice()" mentod in javascript 3. what is the function of slice method in javascript -
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() return an array of an object's set of values in the same order that a for ...in statement would inerate over it.
var picnic={
location:"Dream Lake",
food: "all of my favorite fruits",
other: ["Tajin", "Chamoy"],
transport: "basket",
numberOfItems: 11,
YogiBear: false
};
console.log(Object.values(picnic));
["Dream Lake", "all of my favorite fruits", Array(2), "basket", 11, false]
-
What did you Google to help you with this task, and how did you pick your results? I searched:
1. what is object values method javascript 2. What is Object.values() javascript 3. enumerable computer scicence 3. what are enumerable properties 4. for in loop javascript In order to fully understand this one I had to define enumerable and look up for...in loops. I choose results based off of familiarity with the sorce however I also dug around for different descriptions to try to understand the terms as well as the Object.values() method better.
Imagine that you're taking your favorite board game and turning it into a computer-based game.
-
Name of board game: CHESS
-
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: "CONGRATULATIONS YOU WIN!" "Nice try, you loose."
- Integer and/or float data: 8 68
- Boolean data: true false
- Array data: pieces = ["king", "queen", "rook", "biship", "knight", "pawn"]
- Hash or Object data: Players = { "one" => "white", "two" => "black"}
-
On a blank sheet of paper, create a diagram that shows how you understand iteration working. Be detailed and get creative! When you're done, take a photo of your diagram and post it in the Mod 0 channel on Slack. Your instructor(s) will provide feedback in a thread. (If you're feeling extra fancy, feel free to create your diagram using software instead of pencil and paper)
-
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.
-
Walking. Move left leg. Move right leg. Repeat unil destination is reached. In this example the instructions for each leg are repeated until the condition of desired desitnation is reached.
-
Every year on my birthday I get +1 birthday candles on my cake until I reach 30 years old. This is interation becasue the instructions of adding the previous years number of candles +1 is repeated until the condition of 30 is met.
-
I practice "Folsom Prision Blues" on guitar until I can play it perfectly. This is iteration becasue the act of practicing the same song over and over is a cyclical process that incrimentally results in my desired condition of being able to play the song without making mistakes is made.
-
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 weather app that continuially refreshes to provide the user with constant up to date information. This is an example of iteration because the program has to continuillay repeat it's process to retrieve information and refesh page until the app is closed.
-
Looping through data to find and log participant's ages. Take current year. Subtract birth year to get age. Continue to next participant. This is an example of iteration because the code is giving specific instructions to take current year and subtract birth year to get age. It then moves on to the next set of data and repeats until all participants' ages have been caluclated.
-
Software that is searching a database for the fingerprint of a suspect. Simularly to the above examples the software is using iteration to search each fingerprint in the database until it finds a match.
- 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:
Nice job!