Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save wthompson92/1d5a31115d5912ea794caa5638cae8fb to your computer and use it in GitHub Desktop.

Select an option

Save wthompson92/1d5a31115d5912ea794caa5638cae8fb 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: "Array drop" takes away a desired element from your array and leaves all other elements. If your array included "apples", "bananas", "carrots", and you chose to drop carrots, the program would return "apples", and "bananas"

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

I searches: "array drop" in ruby explain and used the stack overflow information as well as the linked source.

  • 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 allows you to combine new elements into you existing array and tacks on the newest information to the end of your array. If my elements in an array ar "1","2" and I use the puch funtion to ad "3","4" the array will return: "1","2","3","4"

  • What did you Google to help you with this task, and how did you pick your results? "Array Push" funtion, I used stackoverflow.

  • 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 makes all of the words in a variablke their own variable. The string "John, Alice, Fred, Jan" would become "John", "Alice", "Fred", "Jan" when it was split.

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

Googled: "String Split" Ruby programming Source: ruby-doc.org

  • 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 funtion takes a portion of the array that you speicfy and returns it to you. If you slice 5-7 on an array of 7 the program yould return the first four elements.

  • What did you Google to help you with this task, and how did you pick your results? I used developer.mozilla.org and stack overflow. I googled "Slice Funtion" javasscript

  • 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 method giveds the values of an object when used. if i had varaible "apple" with the properties "green, round, sour" the method would return :"green round, sour" when I asked for the object values.

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

I used developer.mozilla.org I googled "Object Values" javascript and used geeksforgeeks.com

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

  • 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: "Resource Types" "Development Cards"
  2. Integer and/or float data: "Odds of rolling a six", "Number of turns"
  3. Boolean data: "If a player rolls a seven, then the thief is moved", "If a player gets 10VP, then the win the game".
  4. Array data: "Players" , "list of all dice rolls"
  5. Hash or Object data: Number of Players Array "Players" Hash: "4", Dice Rolls Currenly Array: "Dice Rolls" Hash: "52"

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.

  • Folding Clothes. The task requires the same action to be given to a series of differt variables. I pick up the shirt, fold, then put away. I pick up the pants, fold and put away, on an on.

  • Paying employees, again the task requires the same a action for each element. I pay Bob, repeat the taskl on the next variable, Karen, then pay Karen.

  • Reading a book. I read the page, finish reading and turn the page until the end of a book.

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

  • Evalutaiong the truth of variables in an array

  • Evaluatiing interegers as greater than or less than in an array.

  • Capitilizng all the first letters of all strings in an array

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, @wthompson92!

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