Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save BrandyMello/e6ad04c0c8d22dd59a74191447da7a07 to your computer and use it in GitHub Desktop.
Save BrandyMello/e6ad04c0c8d22dd59a74191447da7a07 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 "drops" or eliminates the first designated number of elements from the array to return the elements following the designated number. For example: a=[5,10,15,20,25,30] a.drop(2) #=>[15,20,25,30]

What did you Google to help you with this task, and how did you pick your results? define drop method for array in Ruby; what does the array drop method do in Ruby; what does the drop method do for an array in Ruby; what does the "drop method" do for an array in Ruby I read through a few things that didn't make sense after reading the link to the documentation. I kept coming across the word "delete" in other questions. I looked through the video and image tabs. When I clicked on a freeCodeCamp.com link, it clicked.

  • 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 additional elements to the end of the array when returning the array. For example: b=[15,20,25,30] b.push[35,40] #=>[15,20,25,30,35,40]

What did you Google to help you with this task, and how did you pick your results? With the previous question, I landed on freeCodeCamp.com with definitions of "Common Array Methods" and continued using that as a source in combination with the linked documentation.

  • 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 String Method in Ruby splits or breaks up a string into parts (or sub-strings) and returns the parts as an array using whitespace as indicating breakpoints unless another separator is indicated. For example: "This one is still fuzzy." .split #=>["This", "one", "is", "still", "fuzzy."] or "Not:getting:all:the:outcomes:for:alternate:indicators." .split(/:/) #=>["Not", "getting", "all", "the", "outcomes", "for", "alternate", "indicators."] A limit can be added with a comma and the number following the indicator. The last split will be all the remaining data. For example: "1,2,3,4,5,6".split #=>["1","2","3","4,5,6"] If your pattern is a Regexp (a regular expression), the array returned is broken where the Regexp matches the pattern. I do not completely understand this. I can see the patterns and that the corresponding "regexp" code is breaking the string at the obvious places (making the computer think like a human) and returning an array of the pattern, but I do not understand how to create or identify the Regexp.

What did you Google to help you with this task, and how did you pick your results? what does the split method do to a string in Ruby; what does the split method do to a string in ruby; what does the split method do to a string in ruby stackoverflow; example of splitting a regex pattern in ruby -Q: Does a split modify the original string?

  • In your own words, what does the JavaScript array slice method do? As you're explaining, be sure to provide an example.

Your answer: In Javascript the array slice method produces a different array composed of part of the original array indicated by the objects identified. The object in the array count up from zero and you can add a limit or count from the end of the array using a negative number. For example: var students=["Barbara", "Julie", "Jeannine", "Brian", "Garth", "Craig"]; console.log(students.slice(0,3) //expected output: Array ["Barbara", "Julie", "Jeanine"];

What did you Google to help you with this task, and how did you pick your results? I used the MDN link and then Googled javascript array slice and chose to check out a link to w3shcools.com because the definition showing matched the MDN definition. Q's: single quotes vs. double in JS? Semicolons at the end of a line of code in JS? Always, sometimes?

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

Your answer: Javascript Object.values() method returns the enumerable objects (objects set to true) in an array in order, even if the array is not ordered. For example: const object 1 = {c: Carrie, a: Abigail, b: Brianna}; console.log(Object.values(object1)); // expected output: Array {Abigail, Brianna, Carrie}

What did you Google to help you with this task, and how did you pick your results? what does enumerable mean in javascript; went to developer.mozilla.com; what does object.value method do in javascript; 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: Clue

  • 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: characters= "Miss_Scarlet, Mrs_White, Professor_Plum, Colonel_Mustard, Mrs_Peacock"

  2. Integer and/or float data: die_role= 2,4,6,1,3,5

  3. Boolean data: If player guesses Mr. Green and the Revolver and the Dining Room then s/he/they wins the game! true AND true AND true = true true AND true AND false = false true AND false AND false = false false AND false AND false = false false AND true AND true = false false AND false AND true = false

  4. Array data: [Kitchen, Ballroom, Conservatory, Billard_Room, Library, Lounge, Hell, Study]

  5. Hash or Object data: {"card_count" = 21}

3. Iteration (30 min)

  • On a blank sheet of paper, create a diagram that shows how you understand iteration working. Be detailed and get creative! This should not be the simple table that we used during the lesson. When you're done, take a photo of your diagram and send it to Rachel and Tim on Slack. (If you're feeling extra fancy, feel free to create your diagram using software instead of pencil and paper)

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

  • Sorting returned Library books: 1. Pick up each book and look at the call number. 2. Sort each preceding book before or after the first book to order the stack. Repeat for each book.

  • Returning Library books to their shelves: 3. Start at the beginning or end of the sorted stack and find the call number slot on the shelf 4. return the book to it's appropriate slot. Repeat with the next book.

  • Laundry: 1. Sort each piece of laundry by color. 2. choose one color to wash at a time. 3. pick up each garment and look for stains and spray stains. 4. place in wash machine Repeat for each garment until load in in the wash machine.

  • Planting an herb garden. For each plant: 1. Dig a hole. 2. Remove from pot 3. Loosen root 4. Place plant in hole and refill, mound up dirt around base 5. Water Repeat with the next plant.

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

  • Purchasing or adding items to a shopping cart: Each item would need to go through a series of steps or actions before purchased. 1. If it is in stock, add to cart and continue with steps. If not, send message and suggest other similar items. 2. Add cost of item to cart. 3. Add shipping shipping costs and suggested tax to cart. 4. Offer to check out or continue shopping. Repeat for each item added to cart.

  • Sending a welcome email for signing up for a website. Once signup information is submitted, for each block of data, 1. retrieve the user's name and email address. 2. Pull standard "welcome email." 3. Insert user name into letter. 4. Insert email address. 5. Send.

  • Returning Library books. 1. Pull each book from the return bin. 2. Scan the barcode. 3. When the account of the borrower pops up, click the returned button.

@timomitchel
Copy link

Brandy, thank you so much for putting so much effort into these tasks. Your deep-dive will be rewarded once you begin the program. I can tell you have a high level understanding of iteration. For extra practice, can you think of a time when you would need to use nested iteration? How about a way to organize your game into classes or components?

@BrandyMello
Copy link
Author

I was thinking about that when I was writing about the Clue game and my strategy of process of elimination. The classes are rooms, weapons and characters and you cycle through the rooms that you do not have in your hand (they have already been eliminated. In each room you enter you ask about a character and a weapon that you have not already eliminated narrowing down until you know the one of each of the cards that are not in the hands of other players (but in the secret envelope). The strategy I believe is nested iteration. The basic iteration is roll die, move piece, if in a room (true or false) ask a scenario of each class: character, weapon, room. The strategy is another iteration within where you cycle through each of each class.

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