Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions deliverables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Copy link
Contributor Author

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

Why do you need to install Ruby but not HTML/CSS?<br>
Ummmmm....... I pass?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Expand All @@ -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>
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Expand Down
6 changes: 5 additions & 1 deletion deliverables/ruby_monk_problems/array_of_fixnums.rb
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. You can also do false if !x.is_a?(Fixnum) instead of all 3 lines

return false
end
end
end
4 changes: 2 additions & 2 deletions deliverables/ruby_monk_problems/calculator.rb
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
10 changes: 6 additions & 4 deletions deliverables/ruby_monk_problems/color.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use @r, @g, and @b here too. The reason you can access these with just r is because of the line above

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not completely necessary for your first solution. It would return nil if the express was not true and nil is falsey

end
6 changes: 4 additions & 2 deletions deliverables/ruby_monk_problems/exec_time.rb
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

proc.call
Time.now - t
end
2 changes: 1 addition & 1 deletion deliverables/ruby_monk_problems/find_frequency.rb
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?)
7 changes: 7 additions & 0 deletions deliverables/ruby_monk_problems/kaprekar.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
def kaprekar?(k)
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
1 change: 1 addition & 0 deletions deliverables/ruby_monk_problems/length_finder.rb
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
5 changes: 4 additions & 1 deletion deliverables/ruby_monk_problems/my_array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ def initialize(array)
end

def sum(initial_value = 0)
# your code here
return ___ unless block_given?
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
4 changes: 2 additions & 2 deletions deliverables/ruby_monk_problems/non_duplicated_values.rb
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
8 changes: 7 additions & 1 deletion deliverables/ruby_monk_problems/number_shuffle.rb
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
5 changes: 3 additions & 2 deletions deliverables/ruby_monk_problems/palindrome.rb
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(' ','')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be assignment, not ==

str1 == str1.reverse
end
6 changes: 5 additions & 1 deletion deliverables/ruby_monk_problems/random_select.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
def random_select(array, n)
# your code here
ans = []
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
4 changes: 3 additions & 1 deletion deliverables/ruby_monk_problems/restaurant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ def initialize(menu)
end

def cost(*orders)
# your code here
orders.inject(0) do |sum, ord|
sum + ord.keys.inject(0) {|cost, key| cost + ord[key]*@menu[key]}
end
end
end
4 changes: 2 additions & 2 deletions deliverables/ruby_monk_problems/sort_string.rb
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
2 changes: 1 addition & 1 deletion deliverables/ruby_monk_problems/sum_of_cubes.rb
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