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 method [drop] in the Ruby language drops the designated amount of values/data sets from the array as indicated. So if I had an array called familyMembers and I add .drop to it with (2) like this familyMembers.drop(2) and then call the method, the program will remove the two first entries of the array.
Ex: Lets say the array familyMembers looks like this = ["Alexandra", "James", "Bobby", "Sharon"] and I call familyMembers.drop(2), the terminal will update and output my new array which will now look this familyMembers = ["Bobby", "Sharon"]
-
What did you Google to help you with this task, and how did you pick your results?
I googled Ruby array [drop]. The first result that I found was from APIdock.com and gave a brief definition of what the method does. I am familiar with the method from other programming languages so I felt confident that this was a correct explanation.
-
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 method split will break up an array according to my specification in substrings or fractions of the original array. If I provide a value then it will break up the string by removing that value, with each new instance becoming a new substring. Let's say I have a string "ABBA". The method split, which could be called by doing "ABBA".split(//), would return an array comprised of: ["A", "B", "B", "A"]. I could also call it by passing through the value "B", such as "ABBA".split("B") which would return ["A","A"] because there are two times "B" is removed. If I did "ABBA".split("BB") then the output would be only ["AA"]
-
What did you Google to help you with this task, and how did you pick your results?
I searched Ruby string split method, and the first result I had was from APIdock which I just used from the previous example and am confident that the result it provided was accurate.
-
In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example. Your answer:
If I pass the method slice through an array and give it value(s), those values represent the indices of the array and the method removes all the values up to the value passed. For example:
var groceryList = ["Eggs", "Butter", "Pears", "Bread", "Milk"]
and I call console.log(groceryList.slice(2)) then the method will remove from the array the indices 0, 1, which will update groceryList to look like = ["Pears", "Bread", "Milk"]
- What did you Google to help you with this task, and how did you pick your results?
I googled Javascript array slice and saw a posting by MDN further down my results page. I read through it and felt satisifed that this was a correct explanation of the method.
Imagine that you're taking your favorite board game and turning it into a computer-based game.
-
Name of board game: "Survivor"
-
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: "Player1", "Player2"
-
Integer and/or float data: age = 0
Sum of Attributes_of_Player == 100%
-
Boolean data:
x = Math.floor(math.random() * 4)
if (age < 85), age = age + 15
if (age > 50), Attributes_of_Player1.slice[x]
else (Game Over)
-
Array data:
Attributes_of_Player = ["Dexterity", "Problem-Solving", "Hunting", "Intelligence"]
- Hash or Object data:
human(key).eyes = "blue", "brown", "green"
human.skin = "tanned", "dark", "light"
human.gender = "He/Him", "She/Her", "They"
human.hair = "brunnette", "blonde", "red", "black"
-
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.
-
Using my fingers to count to ten. Raise my first finger, and each additional finger is an additional iteration until I reach 10.
-
Checking the calendar until it is my birthday month, starting with a specified month I check if it is April, if not then I wait until next month, and continue until I reach April. The number of iterations depends on what my starting value is.
-
Comparing the amount of money in my wallet and how many 99 cent sticks of gum I can buy. If I have 10 dollars then I would have 10 iterations/ purchases of gum (not accounting for tax)
-
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.
-
Conditional statements (True/False) are based on iterative programming and it is good for if you are trying to write a program that checks if it is someone's birthday. Var = currentMonth Var (i) inputted by user If currentMonth == i console.log("Happy Birthday")
-
If I am trying to performing algebra based on a given value and certain variables then iteration would be necessary. The example of the gum purchase could be translated into code by writing wallet = 10.00 if (wallet < 1.0) wallet = wallet - .99
This would run 10 iterations until wallet = 0.1
- If I am trying to parse through a data set and want to output rounded up values I could write code that looks like
numberList = [2.4, 1.6, 3.5]
i = 0
x = 0
if (i > numberList.length)
y = console.log(numberlist[x]) + .5
console.log(y.toPrecision(1))
x = x++
i = i++
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...Original has braces and the mistake version has parens |
| .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...There is no hyphen between Sans serif |
| 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...Original calls for max score - min score and mistake calls min score - min score |
| 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...Original says A is equal to B and mistake says B is equal to 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...Spelling error in initialize |
- 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:
@JamesRexMiller4 overall nice work on this, remember with the iteration examples to always start with a collection, and to perform an operation for each item in that collection.