Skip to content

Instantly share code, notes, and snippets.

View abloom's full-sized avatar

Andrew Bloom abloom

  • Turquoise Health
  • Chicago Il
View GitHub Profile
def super_fizzbuzz(array)
fizzbuzzed = []
array.each do |num|
if num % 3 == 0 && num % 5 == 0 # return "FizzBuzz"
elseif num % 3 == 0 # return "Fizz"
elseif num % 5 == 0 # return "Buzz"
elseif num /
place
end
# shortest_string is a method that takes an array of strings as its input
# and returns the shortest string
# +array+ is an array of strings
# shortest_string(array) should return the shortest string in +array+
# If +array+ is empty the method should return nil
# array.sort.first
def shortest_string(array)
new_count = [ ]
max_hits = arrayfreq.values.sort.last
array.find_all{ |v| arrayfreq[v] == max_hits }
@abloom
abloom / output.rb
Last active December 15, 2015 17:20
def mode(array)
arrayfreq = array.inject(Hash.new(0)) { |h,v| h[v] += 1; h }
max_hits = arrayfreq.values.sort.last
array.find_all{ |v| arrayfreq[v] == max_hits }
end
# starting with this
mode([1,2,2,2,3,3,4,5,5,5,5])
# after the first line of your mode function, arrayfreq looks like this:
@abloom
abloom / grades.rb
Last active December 15, 2015 16:19
def total(scores)
total = 0
scores.each do |score|
total += score
end
return total
end
def valid_triangle?(a, b, c)
if a**2 + b**2 == c**2
return "true"
else
return "false"
end
end
@abloom
abloom / triangle.rb
Last active December 15, 2015 09:48
def valid_triangle?(a, b, c)
if a**2 + b**2 == c**2
return true
else
return false
end
end
def valid_triangle?(a, b, c)
return a**2 + b**2 == c**2
names = %w(
Andrew\ Bloom
Christopher\ Castro
Diego\ Lopez
Steven\ Targos
Matt\ Milkowski
Christine\ Livingood
Marta\ Contino
)
class View
nameBinding: "model.name"
class Model
name: "andrew"
view.set("name", "rob")
# same as
model.set("name", "rob")
{
"id": 6,
"name": "Campaign with RFPs and IOs",
"budget_cents": 11100000,
"start_date": "2013-04-29",
"end_date": "2014-02-21",
"client": {
"id": 6,
"name": "Kwik-E-Mart"
},