Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jmevans0211/4c3a6a68bad39800c48584ce48d7b512 to your computer and use it in GitHub Desktop.
Save jmevans0211/4c3a6a68bad39800c48584ce48d7b512 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 Ruby array drop method removes the first n elements and returns the rest.

ex: a = [2, 4, 6, 8, 10]

a.drop(3)

#=>[8, 10]

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

I found this method by typing in various Google searches. Some examples of these searches are “what is array drop method ruby”, “‘a.drop’ ruby” and “define array drop method ruby.” Many sources found had similar, if not identical, definitions and examples. I first weeded out examples by date (looking for more recent articles) and site (choosing sites recommended like SlackOverflow).

  • 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 objects to the end of an array.

Ex: a = [“pink”, “green”, “yellow”]

a.push (“orange”, “blue”, “red”]

#=> [“pink”, “green”, “yellow”, “orange”, “blue”, “red”]

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

This method was found with Google searches such as “define ‘array push method’ ruby” and “what is array push method ruby.” Similar to above I tried to first look at dates and then choose familiar sites. Additionally, since a site was given, I did try to diversify sites chosen as many sites found gave similar, or identical, definitions and examples.

  • 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 split method divides up a string into substrings. This can be done in a variety of ways depending on how the code is written. ex:

  1. “i love you”.split #=> [“i”, “love”, “you”]

  2. “super”.split(//, 2) #=> [“s”, “u”, “p”, “er”]

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

To Google this method I searched similar searches as to what is above. For example I Googled, “what is a split string method ruby” and “define split string method ruby.” The first search proved to be much more successful. Again, I weed out searches by prioritizing more recent posts from familiar sites like StackOverflow.

  • 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 cuts out part and keeps part of the array. If the beginning is undefined it assumes that it is 0. ex: var unitedStates = [‘Maine’, ‘Colorado’, ‘Florida’, ‘California’, ‘New Hampshire’] console.log (unitedStates.slice (1, 4)); Output: [‘Colorado’, ‘Florida’, ‘California’]

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

For this method I Googled “what is array slice method JavaScript” and many results came up that, in contrast to my experience answering questions about Ruby methods, differed from the definition on the site given. More recent sites took priority and I made sure that there were enough similarities between the site given and the sites I found to ensure that I was on the right track.

  • 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 value method for JavaScript refers to returning value of the objects of the array in the same order as when it is written with its key. The key is not included, only the value.

ex:

var pet = { animal: “cat” name: “Zombie” age: 7 color: gray };

5/5

expected output (from above): Array ["cat", "Zombie", 7, "gray"]

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

The first thing I Googled was the same as above, “what is object value method JavaScript” and tried to find the most current posts. The next thing I Googled was the word “enumerable” and then “enumerable programming” because I was unsure of the definition and if it meant something different within the world of code. I am still not 100% on this meaning.

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: Checkers

  • 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: “game pieces”, “black squares”, “red squares”
  2. Integer data: number of game pieces, number of squares
  3. Boolean data: Can n piece be skipped? Can n piece be kinged?
  4. Array data: List of black pieces kinged, list of red pieces kinged, list of black pieces off the board, list of red pieces off the board
  5. Hash/object data: Black game pieces (key) and count (value), Red game pieces (key) and count (value). {“black pieces”:12, “red pieces”:12}

5/5

Name of board game: Scrabble

1. String data: "game pieces", "total squares on board"

2. Integer data: points per round, total points per player

3. Boolean data: Is the submitted word a real word? Did the player use at least one letter from a word already on the board?

4. Array data: list of words submitted, list of words submitted by each player, points awarded per round

5. Hash/object data: Points awarded per round {"Round One": 10, "Round Two": 7, "Round Three": 15}. Words submitted each round {"Round One": "brick and king", "Round Two": "gone and burn", "Round Three": "never and ego"}

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.
  1. Laundry - doing laundry is an example of iteration because we wear, clean, and put away our clothes in a cycle, and then repeat.

  2. Doing the electric slide - this dance is repeating the same dance steps over and over again until the song is done. Once you do the steps on all four sides, repeat.

  3. Icing cookies - Each cookie needs to be iced the same way. Once one is done, ice the next cookie the exact way and then move on until all cookies are iced.

5/5

- [ ] 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.

1. Drinking a liter of water for optimal hydration - This could be an iteration because to achieve optimal hydration one would need to drink a certain amount of water every minute (or few minutes) until the liter is finished.

2. Arranging a bouquet - There are a certain number of flowers to be included in the bouquet, and once they've all been arranged the arranging is complete.

3. Reading a book - There are a certain number of pages in a book. Each one is read and then the next and next until all pages are read and book is complete!

  • 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.
  1. Generating/playing a playlist - a song is chosen, played, and then another song is chosen and played. This process continues until the process is interrupted by user discontinuing listening to music.

EDIT: a song is chosen from a collection of 100 songs taken from top 40 hits from 2002. Once one song is played, another song from the collection is played. This process is continued until all 100 songs are played.

  1. Counting number of people who purchased a certain item - Amazon is a good example of this, where it displays how many people bought the item. The item is bought, added to the total, and the displayed on the webpage. This process continues until item is no longer available for sale and taken off the site.

  2. For every number input with letters or float, change to an integer - Let’s say someone is filling out a form online and are asked to input the amount of X, this amount would be changed so the output would always be an integer and never a float or comprised of letters. This process would happen for each input of letters or a float over and over again, repeating for each person filling out the form.

5/5

- [ ] 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.

1. Using the AllTrails application to filter through results - after putting in filters like (distance, gain, ability level, location) the application will go through a collection results and show the user the trails with the applied filters.

2. Payroll - For each employee, software will go through the steps of how many hours worked, hourly wage, PTO (applied or not), to determine the amount on the paycheck.

3. Grading a multiple choice exam online - For each question, software determines if the answer is correct or incorrect, and does that for each question until all questions are reviewed.

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:

  1. One thing I would like clarification on is how not to plagarize. While aspects of this is obvious, don't copy word for word, and don't use the exact same syntax but with synonyms, I am wondering specifically for programming, how is plargaizing defined?

2. This is round two for me so I reviewed some of my answers and redid others. I am hoping my bash profile set up worked okay. There is still the $ symbol at the end... jeannie~$. I noticed in Rachel's video there was no $ symbol. Thank you!

@katiescruggs
Copy link

Nice work, @jmevans0211! Good question about plagiarizing with code. While it's obviously wrong to steal someone's entire application/website, there isn't really a problem with copying small pieces of functionality as far as I know. For example, a common piece of code would be splitting an array into equal parts. If I found that online on stack overflow, I would think it's okay to use it in my own program. If you're worried about plagiarizing, you can always add a comment like // following function from www.stackoverflow.com/....

Make sure for your iteration examples that you're thinking of a collection. A good example is collection: songs in a playlist. They are iterated over and played. But in number of people who purchased an item and change form inputs to integers, there isn't a collection that is being looped over. Instead, those changes are happening based on events (purchase, form submitted).

@jmevans0211
Copy link
Author

Thank you for the clarification, Katie!

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