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: arr.drop(n) will return an array that is composed of the items in the original array after the nth term.
arr = [0, 1, 2, 3, 4, 5, 6]
arr.drop(3) #=> [3, 4, 5, 6]
- What did you Google to help you with this task, and how did you pick your results?
I searched for the terms, Ruby array drop method. I chose a link to docs.ruby-lang.org for a definition and to Stackoverflow.org for how to implement the code. I chose those site are they were both recomended by people I know.
- 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 split method divides a string into an array based on values you specified.
#string delimiter "turing".split('') #=> ["t", "u", "r", "i", "n", "g"] #string delimiter "turing".split('r') #=> ["tu", "ing"]
- What did you Google to help you with this task, and how did you pick your results?
I search, Ruby string split method. I quickly skimmed the results and the descriptions then I found a result on StackOverflow and I went with that as my first attempt.
- 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 slich method extracts a section of a string and returns it as a new string, leaving the original string intact. It can be used to specify location from the begining or the end of the string
var str = "Unlocking Human Potential"
console.log(str.slice(5)); // expected output: "king Human Potential"
console.log(str.slice(5, 19)); // expected output: "king Human Pot"
console.log(str.slice(-4)); // expected output: "tial"
console.log(str.slice(-9, -5)); // expected output: "Pote"
- What did you Google to help you with this task, and how did you pick your results?
I searched, JavaScript array slich method. I have been warnedabout motzilla's site before but I didnot think that the slice method would have change so I went to Motzillia's site because it had the definition in the results summary.
Imagine that you're taking your favorite board game and turning it into a computer-based game.
-
Name of board game: The Setterlers 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:
Name of victory cards, "Longest Road" and "Largest Army" Instruction on Development Cards, "Place 2 newroads as if you had just built them."
- Integer and/or float data:
Integer, number of pieces in a players road.
Integer, number rolled on each die and the sum of both die
- Boolean data:
Is the bandit on a tile
Does a player have enough resources to build a road
- Array data:
Total set of town cities and roads
Total of each type of resource card.
- Hash or Object data:
Land and production
Development Card titles and instruction
Victory Card Titles and point value
Port and Trade in ratios
- 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. Repeat placing one foot infront of the other until a condition is met. The condition could be arriving at a desired location (condition controlled) or traveling a specific number of steps (count controlled).
Folding Clothes. An item of clean clothing is taken out of a container, then folded. The process is then repeated until all of the clean items have been folded.
Weight lifting. An excersize is performed under specific condition a specified number of times. Lift, put down, now repeat for 15 reps.
- 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.
Creating address lables from a database of people. The program would need to search for a person's name, street address, city, state, and zip code. Place the data in the correct location and then repeat the proces for the remaining people in the database. The iteration is the repeated process that the program would need to perform to create the list of address lables.
Printing an attendance record for a class. The program would need to gather first name, last name, and attended for each student assigned to the class from a database and print each set.
Printing a list items in a directory. The program needs to gather the name and item type of an item in a given directory print the item or add it to an array. The program wojuld then need to repeat the process for every item in the directory.
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 curly bracket should have been used after the # and parenthesis were used. |
| .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 is missing the hyphen |
| 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 max was switched for min. |
| 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 the a in { |a,b| a == b }. was replaced with 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 second i in def initialize(data) is missing |
- 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:
- What did the $ at the end of the code change (export PS1="\u\w`parse_git_branch`$ ")? It was differrent than the code that Rachel pasted in but only slightly.
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.