Skip to content

Instantly share code, notes, and snippets.

View kayline's full-sized avatar

Molly Trombley-McCann kayline

View GitHub Profile
@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
@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 / 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)