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 arr drop mehtod will remove the preceding elements in the array not including the specified index. Example: s = [1,2,3,4,5,6,7] s.drop(5) Output: [6,7] As you can see. It will include the value of the first index and drop everything before it.
Other example:
s = [1,2,3,4,5,6,7] s.drop(4) output: [5,6,7]
-
What did you Google to help you with this task, and how did you pick your results?
I googled 'ruby drop method reddit' and 'ruby drop method stack overflow'. I even youtubed it and saw how it was performed live and got my best answer from that video.
-
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 breaks up a string into an array of substrings. Assuming the delimiter is the parenthesis falue after the .split(#,#) <---
Example: "how now brown cow?".split Output: ["how","now","brown","cow"] (the contents of the string are th delimiter, and it was spaced out in the array via the white space in the string.
- What did you Google to help you with this task, and how did you pick your results?
I started off with the usual "what does ruby string split method do?" Saw some stack over flow responses and some other websites I never even heard of. some of the sites were references for books and purchasable texts.
- 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 slice method shows a new array based on (1,2) 'index parameters' which are inclusive of the first # but not the second #. If you only insert 1# in the 'slice parameter section ()", the output will include the second index and everything that comes after.
Example: var color = ['blue','red','green','orange']; console.log(color.slice(1)); (only begin slice specified) output: ['green','orange']
Example2: var names = ['sam','scott','david','brett','carl','ryan']; console.log(names.slice(1,4)); output: ['scott','david','brett']
-
What did you Google to help you with this task, and how did you pick your results?
I went to stack overflow for this one. I googled 'js array slice method stack overflow' and got some pretty decent results. It seems to be the less complex the method or function the more results you will get. But that doesnt make them all reliable...
Imagine that you're taking your favorite board game and turning it into a computer-based game.
-
Name of board game: Dungeons and Dragons______
-
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: Character name, Character class (archer,mage etc.)
- Integer and/or float data: Player age(int), Crtibased % damage taken (float), # of dice(int)
- Boolean data: Hero specific inflictions based on class(if hero class = true, take x amount of damage) Coin flip based events(if heads=false, if tails=true)
- Array data: player inventory(items in someones bag, weapons potions etc) Dungeon specific Rewards( dungeon1 = ['sword','gold','clothing'] **items limited to this dungeon]
- Hash or Object data: creature type identification?...key value pairs might be (dragon:fire...all dragons are of the type fire) Map locations ... (City:Midlandia)
-
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.
-
A teacher grading a class of x amount of students exams. In real life there is a specified collection, or number of students. The iteration is the teacher grading the test, until the collection limit is reached.
-
A doctor treating x amount of patients. A doctors office has a waiting room or queue. The iteration is servicing 1 member of that queue and then the next until the queue limit is reached.
-
A cashier ringing up x amount of groceries. A cashier has to ring up a certian amount of groceries per customer. the iteration is ringing up each item until said customer is out of groceries and is ready to pay.
-
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.
-
iphone lock screen password authentication. The system will iterate if the user enters a wrong password for x amount of times until either the user enters valid credentials or the system locks them out. (LOOPS and IF statments) maybe comparing key value pairs?
-
'are you a robot' identification pages for webistes with multiple images. Sometimes when you sign up for a website you have to select the correct image for sometimes 3 iterations...to prove you are sentient.
-
maybe in mathematics when creating a facotiral function. setting i = to an integer for example and having to iterate the multiplication of all the preceeding values until you get to that number.
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... the false statement is using parenthesis() instead of brackets{}. This would be classified as a syntax error. |
| .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...in the font-family attribute there is no '-' between sans and serif. This would be classified as a syntax error. |
| 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...Our formula is incorrect. Within the first section of the dividend it should read 'max' not 'min' . While the program might still compile and run, this would not give us our desired output so it would be classified as a logic error. |
| 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...This is another logic error. Instead of comparing a==b we are comparing b==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...This one was hard to catch but the 'i' in initialize is missing. this would throw an error while compiling. |
- 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: Please let me know if I need to go more in depth on any of the quesitons or if I possibly misenterpreted any of the questions!
Overall, great work on this! I particularly liked your iteration examples and how you were sure to start with collections.