Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save tylorschafer/98612346a81c0c69a755f1314ef9a9d0 to your computer and use it in GitHub Desktop.

Select an option

Save tylorschafer/98612346a81c0c69a755f1314ef9a9d0 to your computer and use it in GitHub Desktop.
Mod 0 Session 2 Practice Tasks

Session 2 Practice Tasks

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.

1. Documentation and Googling (75 min)

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 will "drop" a specified number of elements from an array and returns the remaining elements.

employee_ids = [22, 44, 66, 88]

employee_ids.drop(1)

#=> [44, 66, 88]

In this example of the drop method I chose to drop just the first element in the array and printed the following 3 employee numbers.

  • What did you Google to help you with this task, and how did you pick your results?

    I googled "drop method ruby" and chose the result on rubycuts.com based on their numerous examples and similarity to the included ruby-doc link.

  • 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 would be the opposite of the drop method in that you push the included elements onto the end of the array.

employee_ids = [22, 44, 66, 88]

employee_ids.push(110, 132)

#=> [22, 44, 66, 88, 110, 132]

Using the same example for consistency I used the 'push' method to add two more employee numbers (110, and 132) to my array.

  • What did you Google to help you with this task, and how did you pick your results?

Similar to the last example I google "push method ruby", but ended up using ruby-doc info as this method was very similar to the drop method, and I felt I had a strong grasp on how to use it.

  • In your own words, what does the Ruby string split method do? As you're explaining, be sure to provide an example. Your answer:

This method is more complicated than the last two, but from my understanding the basic idea is the 'split' method will split a string based on an included character(s).

"Tylor Schafer".split

#=> ["Tylor", "Schafer"]

In this example my full name is technically split into two strings of "Tylor" and "Schafer"

  • What did you Google to help you with this task, and how did you pick your results?

I googled alot more info on this method. I googled "split string method" and "split string method examples" and used search tools to give me results posted in the last year. The website thoughtco.com had some great examples that helped me gain better perspective on the split method.

  • 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 basically makes a copy of a subset of an array list. In essence you are selecting only a portion of an array to copy without changing your original array.

var beatles = ['Paul', 'George', 'John', 'Ringo'];

console.log(beatles.slice(1, 3));

Output should be: Array ["George", "John"]

In my example I am starting the slice after the first name 'Paul', and ending it after the third name 'John', therefore cutting off the first and last names 'Paul' and 'Ringo'.

  • What did you Google to help you with this task, and how did you pick your results?

I googled "javascript array slice" and found a great article on zendev that explained the slice method very well. I used this in combination with the devloper.mozilla site to create my 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 values method in Javascript is used to return an array of an objects own values. From what I learned my research, Javascript doesn't have traditional classes compared to other languages.

const tylorSchafer = { a: 'Tylor Schafer', b: 29, c: 'Student' };

console.log(Object.values(tylorSchafer));

Output should be:

Array ["Tylor Schafer", 29, "Student]

I basically used objects values method here to list my profile traits in an array, pulling the information from the values of my tylorSchafer object.

  • What did you Google to help you with this task, and how did you pick your results?

I googled "object.values javascript method" and "object.values method javascript use". I chose the sights geeksforgeeks.org and appdvidend.com as they had recent postings with good explanations and lots of demo code.

2. Data Types (15 min)

Imagine that you're taking your favorite board game and turning it into a computer-based game.

  • Name of board game: Life

  • 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.

  1. String data: Player Name ("Tylor"), Name of Careers ("Teacher", "Doctor", "Musician", etc), Action card statements ("Your pet goat wins a ribbon!")
  2. Integer and/or float data: Player career salary (Integer: 30k - 150k), Total net worth (Integer). There really isn't any place for float data in this game.
  3. Boolean data: This would be used alot in the 'Stop Spaces'. At the beginning of the game you would choose to 'go to college' or 'start career'. At the Night school stop you would choose to change your career or keep your current career. At the family stop you would choose to take the family path or continue on the life path.
  4. Array data: I would use an array to arrange all the data on the players including: Names, Careers, and Salaries.
  5. Hash or Object data: Hashes in this game would pair together the players name data with their relevant career, salary, house, etc. This is different than the array in that the object/hash is what keeps track of the players data individually. Whereas the arrays would be linked to a single specific category such as player salaries.

3. Iteration (30 min)

  • 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.

  • Washing dishes - Washing dishes is a multi step process of taking a 'dish' and applying cleaning steps (place in hot soapy water, scrub, dry) and repeating this processes for the next 'dish'.

  • Paying bills - Paying bills is another multi step process of starting with a 'bill' and applying payment steps (access website, access your bill, choose payment type for bill, finalize payment) and then repeating this processes with your next 'bill'.

  • Packing clothes for a trip - In this example you would choose a piece of clothing and start a process of: determining it's suitability on your trip, folding the clothing, and placing it in your suitcase. You would then repeat the whole process for the next piece of clothing. Theres not really a good singular word for clothes, but I think it's still a good example of real life iteration.

  • 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.

  • Loyalty member signup - This is what I used for my diagram this week, and I believe it is a good example of programming iteration. At checkout, a customer would be asked a boolean question of "are you a loyalty member?", and then would be taken through a series of steps of either supplying their loyalty information, signing up for a loyalty membership, or saying no to signing up for a membership. This process would be repeated for every customer at checkout.

  • Accepting website terms of agreement - On websites where you would want visitors to accept certain terms of agreement or perhaps agree to a cookie policy, you could use iteration. You would first prompt the user with policy changes, ask the user to read the changes, then ask the user to agree to the agreement. This would be repeated for each unique vistor.

  • Verifying visitor age - On a website where you wanted to verify a users age you could use iteration. Each time a vistor accesses your site you would ask them to supply a birthdate, calculate the users age, and then give a boolean response of either welcoming the visitor to the site, or denying them access to your site because of age restrictions. Once again this would be repeated for every unique vistor accessing the website.

4. Modify your Bash Profile (10 min)

  • 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\`$ "

5. Questions/Comments/Confusions

If you have any questions, comments, or confusions from the any of the readings that you would an instructor to address, list them below:

@katiescruggs
Copy link

Nice work, @tylorschafer! For your programming iteration examples, make sure that you are starting with a collection of things to loop over. It seems like most of your programming examples involve waiting for a user to visit website, waiting for a user to do something before running through a series of tasks. True iteration would be having a line of users, and looping through them to do tasks instead of waiting for them to do something that kicks off the process.

@tylorschafer
Copy link
Author

tylorschafer commented May 9, 2019 via email

@katiescruggs
Copy link

Hi @tylorschafer, you do not need to resubmit new examples. I am mostly looking for completion and effort for your Mod 0 homework, so you have full credit. If you'd like me to check some iteration examples for you to make sure you have the concept down before assessments, I'm happy to do so! Feel free to DM me on Slack with those -- I usually respond fastest that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment