Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save CLLane/44410513afdd2660cbe0aa72558c2ab2 to your computer and use it in GitHub Desktop.
Save CLLane/44410513afdd2660cbe0aa72558c2ab2 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 in ruby will drop/skip a section or individual item in an array. For example if you were to input: element.drop(3) would drop the first 3 items in the array and return the remainding items. If your input read element.drop(0) it would drop/skip none of the items in the array and return it as a whole.

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

I tried a couple of searches but settled on: "what is the purpose of "drop method" in ruby." I found that putting "drop method" in quotes returned more specific and valuable results. I decided to go with a website that was technical but simple in its explanation, I referenced it against a few other results and checked its validity by way of last modified date.

  • 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() command in ruby, pushes objects into an array, for example if you were to input element.push("item") this would push "item" into an array named element.

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

I googled a few things but the results that worked best for me came from the search: "What is the purpose of push in Ruby." This resulted in a few valuable results two of which were a bit technical in their explanation and went slightly over my head, I settled on a website geared toward beginners that provided a simple explanation. I decided to trust the website by cross referencing it with the more technical sites, and by checking its date last modified which was current.

  • 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 string split method takes a user input and seperates/splits them into individual strings. For example if a user was asked to enter their full first and last name that input would have to be split into two seperate strings before it could interact as a "first" and "last" names independently in your code. You would use the split method to return just a portion of a users input.

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

In order to find an answer to the question I searched: "use of "string split method" in ruby." I once again used quotes around "string split method" to help get a more specific page of results, and from there used a stackoverflow.com page but it proved to be a little more indepth than I needed, so I returned to by results and found a more tutorial/beginner geared sight that had a better explanation of the code.

  • 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 slice() method is used to return a segment of an array without changing the orignal array itself, for example if I had: var = pets [ "snake", "dog", "cat"]; and wrote var mammals = pets.slice(1) it would return: dog cat. The .slice method calls for .slice(start, end) where end is an optional and if ommited the .slice will stop when the array ends. It is similar to the ruby drop method.

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

    I used the google search: "meaning of javaScript "slice method"." I used the name of the language that I was using and threw the method I was researching in quotations to specify my search. The results came up and the first response was a current explanation from a trusted site and it explained things in a way I could understand so I went with it.

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

By using the Object.values() command in javaScript you can create an array consisting of the values of the given object. For example if you have an object defined as grocery and write Object.values(grocery) your output will be an array that includes all the values defined in the object grocery.

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

I searched: "meaning of javaScript "object values"." I used the name of the language I was using, and quotes of the exact phrase I was searching for, and I used the word meaning instead of how to because I was looking for a definition. The results page loaded and I scrolled through them found a trusted website with an up to date response.

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

  • 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: "players_Name" "Letters"
  2. Integer and/or float data: "Value of a letter" "Letter Count" and "Multiplier of tile"
  3. Boolean data: "Is the series of letters a word" and "Does the series of letters use a multiplier tile"
  4. Array data: "Total letters in the game" , "Numbers of points scored by each player" , "Total value of a word played"
  5. Hash or Object data: "The value of a letter piece" , "the multipler of a specific tile space"

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.
  • For running your collection would be feet, the action would be 1. lift backfoot 2. move foot forward 3. place foot down, then you would repeat find back foot, lift, forward, place, repeat.
  • Cutting Carrots your collection would be carrot, the action would be 1. peel carrot 2. cut carrot 3. put carrots in a stew, and 4. get carrot and repeat until carrots are gone.
  • Roll call in school, the collection would be all the students names in the class 1. call out student name 2.wait for response 3. response = hear , no response = absent, move to next name and repeat untill all names are called.
  • 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.
  • You couple create a multiplication game where, A multiplication problem is presented, and if answered correctly another problem is presented and so and so on until a the wrong answer is presented and exits the loop.
  • Creating a list of items in a resturant you could make a inventory program that presents the user with an item and asks for the amount, Once the amount is entered the program will pull another item and ask for the amount, and this process will be repeated until all items have an amount attributed to them.
  • Paying employess can be done by a program as well, Where a list of employees names attached to their hourly pay will prompt a program to find the hours each employee has worked and return a paycheck for each employee and will continue until all employess are paid.

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, @CLLane! For your iteration examples, make sure that you're thinking about a collection of things where each thing will undergo a process. Most of your examples look great, but the one about running and the multiplication game are more of loops that keep going until an end condition is met instead of iterating over a set number of items.

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