Last active
January 30, 2017 17:07
-
-
Save Cdale3/a349523ff63fb5f1cd5556968abc69aa to your computer and use it in GitHub Desktop.
Week 1 Diagnostic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Week 1 Diagnostic | |
Floats and Integers | |
What’s the difference between a float and integer? | |
float is a number with a .2545234 -- not a whole number - | |
an integer is a whole number -- 1, 2, 3 | |
What’s are the similarities and differences between BigNum and FixNum? | |
can't think of it off the top of my head. Will look later and smack myself for forgetting | |
* bignum . -- similiarites for both hold whole numbers they can't accomodate deciaml points bignum is going to be over 19 digits | |
* fixnum -- is smaller than that | |
What will 4.0 / 2 return? | |
2.0 | |
What will 1.5.to_i.to_f return? | |
seems like it would return nil. | |
if the code works the way it sounds, then I think it will show 1.0. I feel like it doesn't round, but it drops the .5 and then turns 1 into 1.0 for the float representation. | |
What part of this expression ("hi" * 5?) is “syntactic sugar”? What does that mean? | |
the ? i think. Syntactic sugar is something that is used in ruby through code representation. It's like a pre-determined ruby "gem" that already has standard procedures of doing things without being programmed to do so. | |
** the * was the correct part | |
What will 10 % 3 return? | |
1 | |
What will 5 == 10/2 return? | |
true | |
* right side evaluates first, order of operations | |
How can you write 5 to the 2nd power? | |
5**2 | |
Strings | |
How can you grab the substring “ell” from “hello”? | |
"hello"[1..3] | |
Give an example of string concatenation and string interpolation. | |
"this is " + "string" + " concatenation." | |
"this is #{string} interpolation." | |
Give examples of three variable names: a “valid name” (it will work) that goes against Ruby style, an “invalid” name (it will trigger an error), and a valid and stylistically conventional name. | |
this_file.rb *greeting = "hello" | |
3stories.rb *3stories = "not good" | |
StarWars.rb *StarWars = "not good" | |
originally read the question for file names not variables | |
Arrays | |
How do you add to an array? | |
.push << -- you can also use .unshift | |
What will [1,2,3].shuffle do? | |
it will rearrange the given contents | |
What do shift and unshift do? | |
shift removes the first element of the array | |
unshift adds to the front of the array | |
Name 3 ways to retrieve 4 from this array: [4,3,5] | |
[4,3,5].first [4,3,5][0] [4,3,5].shift *[4,3,5][-3] | |
How would you print each word from this list (["hello", "goodbye", "cactus"]) to terminal within this output: | |
The word is "hello". | |
The word is "goodbye". | |
The word is "cactus". | |
word = ["hello", "goodbye", "cactus"] | |
"The word is #{word[0]}" | |
"The word is #{word[1]}" | |
"The word is #{word[2]}" | |
Couldn't figure out without using notes, how to make the array stay in it's own set of quotes, everything seemed to join it together. | |
**["hello", "goodbye", "cactus"].each do |word| | |
puts ''The word is /"#{word}.'' | |
Flow control | |
What’s the difference between a while and until loop? | |
while -- as long as the condition is true it will work, as soon as it becomes false it stops | |
until -- as long as the condition is false, as soon as it becomes true it will stop | |
How do you escape a pry in the middle of a loop? | |
exit, next | |
Enumerables (.each) | |
What is the purpose of an enumerable? | |
to iterate through a collection of data | |
What are the two different ways that you can represent a block? | |
[1,2,3].each {|number|} multi-line and single-line blocks I can't remember the single right now. | |
each do |num| | |
"do something" | |
end | |
Given this array ["Beth", "Lauren", "Ilana"]. How would you create a new array of just the first initials of each name? | |
arr = [] | |
arr << ["Beth", "Lauren", "Ilana"][0][0] | |
arr << ["Beth", "Lauren", "Ilana"][1][0] | |
arr << ["Beth", "Lauren", "Ilana"][2][0] | |
** ["Beth", "Lauren", "Ilana"][2][0].map { |name| name[0]} | |
Classes and instance methods | |
When you’re defining a class, how do you store attributes? | |
in the initialize method you use instance variables | |
What is the difference between attr_readers, attr_writers, and attr_accessors? What do each do? | |
reader - replaces a getter method, which retrives an instance variable, writer --and sets or resets an instance variable accessorr -- does both read and write options. | |
What method corresponds with .new when you create a new instance of a class? | |
initialze | |
Methods, arguments and scopes | |
Describe the scope that methods create. Are variables created in that scope accessible elsewhere? | |
local scope. No, the variable is only accessible to the method it is contained in. | |
What does the method scope have access to? | |
the global scope |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment