Skip to content

Instantly share code, notes, and snippets.

View SolomonHD's full-sized avatar

Solomon Hilliard SolomonHD

  • Emory University
  • Atlanta,GA
View GitHub Profile
@SolomonHD
SolomonHD / 04MAR15
Created March 4, 2015 14:07
04MAR15 Gist Solomon
require 'minitest/autorun'
require 'minitest/pride'
# Write two classes which inherit from the Vehicle class below. You will also
# need to add a method to the Vehicle class during this challenge.
class Vehicle
def initialize(make, model)
@make = make
class OddArray
def initialize(odd_array)
@odd_array = odd_array
end
def to_a
odd_only_array = []
@odd_array.each do |number|
if number.class == Fixnum && number.odd?
odd_only_array << number
@SolomonHD
SolomonHD / 02MAR15.rb
Created March 2, 2015 14:20
02MAR15 Quiz
require 'minitest/autorun'
require 'minitest/pride'
# Write a class which has an initialize method, a reader method, a private
# method, and a class method.
# WRITE YOUR CODE HERE.
class Goat
def initialize(name = "default")
@name = name
@SolomonHD
SolomonHD / 26FEB15
Created February 26, 2015 14:24
26FEB15 New Ruby
require 'minitest/autorun'
require 'minitest/pride'
# Write a method which accepts an array and returns a sum of the elements in the
# array. Specifying a second parameter (e.g. 3) will allow you to sum all the
# items starting from index 3. Specifying three parameters will allow you to sum
# between two indices (e.g. everything between 3 and 6, inclusive).
# WRITE YOUR CODE HERE. Name your method `subsum`.
def subsum(array, x = -1, y = -1)
@SolomonHD
SolomonHD / 25FEB15 Quiz
Created February 25, 2015 14:13
Palindrome
require 'minitest/autorun'
require 'minitest/pride'
def palindrome?(input)
input.downcase!
array = input.split(" ")
array = array.join
input2 = array.to_s
if input2 == input2.reverse
return true
@SolomonHD
SolomonHD / 24FEB15
Created February 24, 2015 16:35
24FEB15
require 'minitest/autorun'
require 'minitest/pride'
# Write a method which accepts an array and returns a hash. Each item in the
# array will be a string, and the returned hash should have last names as keys
# and first names as values.
# WRITE YOUR CODE HERE. Name your method `names`.
def names(array)
require 'minitest/autorun'
require 'minitest/pride'
require 'prime'
# Write a method which returns the first n primes, where n is provided to the
# method as a parameter.
#
# Remember that the % operator (modulo) is your friend. It returns a zero if one
# number is divisible by another number. In other words, 4 % 2 == 0.
@SolomonHD
SolomonHD / 18FEB15
Created February 18, 2015 14:23
18FEB15
require 'minitest/autorun'
require 'minitest/pride'
# Write a method which accepts an array as the first paramater and a number
# as the second parameter. Return true if two of the numbers in the array sum
# to the second parameter.
# WRITE YOUR CODE HERE. Name your method `complements?`.
def complements?(array, sum)
if array == nil || array.length < 2
@SolomonHD
SolomonHD / sql_statements
Created February 18, 2015 08:05
SQL Statements
#1
SELECT * FROM authors WHERE email = "shakespeare@example.com"
#2
SELECT * FROM authors ORDER BY created_at DESC LIMIT 1;
#3
SELECT question_text, count(*) FROM questions GROUP BY question_type
#4
@SolomonHD
SolomonHD / 17FEB14.rb
Created February 17, 2015 14:20
17FEB14 Quiz
require 'minitest/autorun'
require 'minitest/pride'
# Write a series of methods which use the .any, .all, .map, .select, .reject, and
# .reduce methods in Enumerable. Each of your methods should be one line.
# WRITE YOUR CODE HERE. In this challenge, names longer than 5 characters are
# considered long.
def has_even?(array)
array.any? {|n| n % 2 == 0}