-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nick White - Week 2 Ignition Assignment - Ruby #6
base: master
Are you sure you want to change the base?
Changes from all commits
9cce9c5
e05f2e7
cb69530
8d292ce
f98a779
32e2984
98f6091
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ | |
###Intro to the Back End | ||
####Required | ||
What is the difference between front- and back-end development?<br> | ||
Why do you need to install Ruby but not HTML/CSS? | ||
Front-end is what a user can see and use. The back-end is the naughty bits doing all the dirty work behind the scenes<br> | ||
Why do you need to install Ruby but not HTML/CSS?<br> | ||
Ummmmm....... I pass? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Come on |
||
|
||
Read the [intro to back end on the Odin Project](http://www.theodinproject.com/web-development-101/introduction-to-the-back-end) description, and the [What is: Back-end web development](http://blog.generalassemb.ly/what-is-back-end-web-development/) blog post. | ||
|
||
|
@@ -12,16 +14,28 @@ Sign Up for Cloud9 and create a basic Rails project. | |
####Required | ||
|
||
What is an "interpreted" language?<br> | ||
A language that can be implemented/executed immediately without the use of a compiler<br> | ||
What is IRB?<br> | ||
Interactive Ruby Shell<br> | ||
What are Objects?<br> | ||
An abstract data type with abilities like inheritance<br> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Data wrapped with functionality |
||
What are Methods?<br> | ||
Functions... Don't know why they're not named functions<br> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. haha I call them functions all the time |
||
What are Classes?<br> | ||
A template for creating objects<br> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Close. In Ruby, Classes are actually objects too. It's a template for creating instances |
||
What are Blocks?<br> | ||
Groups of code essentially<br> | ||
What is an Array?<br> | ||
A series of objects grouped together providing easy data manipulation, vector/pointer use, etc...<br> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indexed is the key |
||
What is an Iterator?<br> | ||
An object that traverses other objects like arrays or lists<br> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or any collection. Good answer though |
||
What are hashes?<br> | ||
Applies keys/id's to data objects to ease searching, sorting and other functions<br> | ||
What is a library?<br> | ||
What is a gem? | ||
A collection of resources used by programs/programmers<br> | ||
What is a gem?<br> | ||
Rubygem..? Essentially a library for Ruby<br> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Downloadable and installable and versioned |
||
|
||
|
||
Do the challenges at http://tryruby.org/levels/1/challenges/0. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
def array_of_fixnums?(array) | ||
# Write your code here | ||
array.each do |x| | ||
if !x.is_a? (Fixnum) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice. You can also do |
||
return false | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
class Calculator | ||
def add(a, b) | ||
# your code here | ||
a + b | ||
end | ||
|
||
def subtract(a, b) | ||
# your code here | ||
a - b | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,18 +7,20 @@ def initialize(r, g, b) | |
end | ||
|
||
def brightness_index | ||
# your code here | ||
(299*r + 587*g + 114*b) / 1000 #why not @r, @g and @b | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use attr_reader :r, :g, :b which automatically defines getters for all of those instance variables |
||
end | ||
|
||
def brightness_difference(another_color) | ||
#your code here | ||
(brightness_index - another_color.brightness_index).abs | ||
end | ||
|
||
def hue_difference(another_color) | ||
#your code here | ||
(r - another_color.r).abs + (g - another_color.g).abs + (b - another_color.b).abs | ||
end | ||
|
||
def enough_contrast?(another_color) | ||
# your code here | ||
if brightness_difference(another_color) > 125 && hue_difference(another_color) > 500 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just return the result of this expression, so def enough_contrast?(another_color)
brightness_difference(another_color) > 125 && hue_difference(another_color) > 500
end a common code smell is when you are evaluating an expression then returning boolean values. You can generally just return the expression |
||
return true | ||
end | ||
return false #Necessary? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not completely necessary for your first solution. It would return |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
def exec_time(proc) | ||
# your code here | ||
end | ||
t = Time.now | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
proc.call | ||
Time.now - t | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
def find_frequency(sentence, word) | ||
# Your code here | ||
sentence.downcase.split.count(word.downcase) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
is_an_experienced_programmer = # Fill your expression here | ||
is_an_experienced_programmer = | ||
candidate.languages_worked_with.include? 'Ruby') && | ||
(candidate.years_of_experience >= 2 || candidate.github_points >= 500) && | ||
! (candidate.age < 15 || candidate.applied_recently?) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
def kaprekar?(k) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good work on this one |
||
ksq = (k*k).to_s | ||
digit = k.to_s.size | ||
|
||
left = ksq.size.even? ? ksq[0..digit-1] : ksq[0..digit-2] | ||
right = ksq[-digit..-1] | ||
|
||
k == right.to_i + left.to_i | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
def length_finder(input_array) | ||
input_array.map {|i| i.length} | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ def initialize(array) | |
end | ||
|
||
def sum(initial_value = 0) | ||
# your code here | ||
return ___ unless block_given? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return array.inject(initial_value, :+) unless block_given? |
||
sum = initial_value | ||
array.each {|x| sum += yield(x)} | ||
sum | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
def non_duplicated_values(values) | ||
# Write your code here | ||
end | ||
values.find_all {|x| values.count(x) == 1} | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
def number_shuffle(number) | ||
# your code here | ||
uniq_combos = number.to_s.size == 3 ? 6 : 24 | ||
digits = nunmber.to_s.split('') | ||
combos = [] | ||
combos << digits.shuffle.join.to_i while | ||
combos.uniq.sort != uniq_combos | ||
combos.uniq.sort | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
def palindrome?(sentence) | ||
# Write your code here | ||
end | ||
str1 == sentence.downcase.gsub(' ','') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be assignment, not |
||
str1 == str1.reverse | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
def random_select(array, n) | ||
# your code here | ||
ans = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like a lot of copy pasta. Did you just change some variable names in some of these? |
||
n.times do | ||
ans << array[rand(array.length)] | ||
end | ||
ans | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
def sort_string(string) | ||
# your code here | ||
end | ||
string.split(' ').sort{|x, y|x.length<=>y.length}.join(' ') | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
def sum_of_cubes(a, b) | ||
# Write your code here | ||
(a..b).inject(0) {|sum, num| sum + num*num*num} | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Points of for being PG-13? Nah...