Skip to content

Instantly share code, notes, and snippets.

View kayline's full-sized avatar

Molly Trombley-McCann kayline

View GitHub Profile
@kayline
kayline / pad_array
Created March 20, 2013 02:46
DBC Prework - Pad an array. In the second method, removing "clone" from line 17 causes the code to fail the 4th spec test, for padding the array with "apples". Why? It seems like all that should do is cause it to fail the 3rd spec test, for a non-destructive method.
class Array
def pad!(min_size, value = nil)
array = self
diff = min_size - self.length
if diff <= 0
return self
else
diff.times do
array.push(value)
@kayline
kayline / gist:5210557
Created March 21, 2013 03:52
Reverse Polish Notation Calculator. Can do recursively?
class RPNCalculator
def evaluate(input)
puts "BEGIN NEW CALC"
stack = []
puts "Initial input is #{input}"
until input == ""
item = input.match(/\A\S*/)
puts "Current item is #{item}"
item_string = item.to_s
@kayline
kayline / gist:5210561
Created March 21, 2013 03:53
Reverse words. Seems to work but the Rspec fails
def reverse_words(str)
array = []
result = ""
str.each_line(" ") { |s| array.push(s.reverse)}
array.each do |i|
result = result + i +" "
end
result = result.chop.lstrip
puts result
return result
# Determine whether a string contains a Social Security number.
def has_ssn?(string)
#check overall length
if string.length < 11
return false
#check for match
elsif string.match(/\d{3}(-)\d{2}(-)\d{4}/)
return true
else
return false
@kayline
kayline / Fibby Try One
Created March 22, 2013 02:32
First attempt at identifying Fibonacci number-foiled by floating point inaccuracy in large values
def is_fibonacci?(i)
puts "The number to test is #{i}"
sum_test = 5 * i ** 2 + 4
diff_test = 5 * i ** 2 - 4
puts "Sum test = #{sum_test} and diff test = #{diff_test}"
sum_test_intrt = (sum_test ** 0.5).to_i ** 2
diff_test_intrt = (diff_test ** 0.5).to_i ** 2
puts "Rounded sum root = #{sum_test_intrt} and diff root = #{diff_test_intrt}"
if sum_test == sum_test_intrt && diff_test != diff_test_intrt
puts "Fibby!"
https://github.com/kayline/ar-student-schema.git

Instructions:

  1. Download this application skeleton.
  2. Convert the app to use AJAX.
  3. Add any files you changed to your gist and submit your code.
/* Here is your chance to take over Socrates!
Spend 10 minutes on each of the following hacks to the socrates website.
Enter them in the console to make sure it works and then save
your results here.
Choose a new pair for each. Add your names to the section you complete.
*/
/* Here is your chance to take over Socrates!
Spend 10 minutes on each of the following hacks to the socrates website.
Enter them in the console to make sure it works and then save
your results here.
Choose a new pair for each. Add your names to the section you complete.
*/
@kayline
kayline / zoo.js
Last active December 17, 2015 16:19 — forked from dbc-challenges/zoo.js
//------------------------------------------------------------------------------------------------------------------
// YOUR CODE: Create your Zoo "object literal" and Animal "constructor" and "prototypes" here.
//------------------------------------------------------------------------------------------------------------------
var Zoo = {
animals : [],
init : function(animal_array){
animals = animal_array;
},
animals : function(){
return animals