Skip to content

Instantly share code, notes, and snippets.

@waneka
waneka / gist:6075634
Created July 24, 2013 23:38
Socrates wants Array#pad! to be destructive and Array#pad to be non-destructive. when i run the code in my console, everything appears to operate just fine. however, socrates is giving me an error for Array#pad operates non-destructively. any help?
class Array
def pad!(min_size, value = nil)
while length < min_size
self << value
end
self
end
def pad(min_size, value = nil)
if min_size > length
@waneka
waneka / gist:6051477
Created July 22, 2013 05:30
Why is this printing multiples of 5 instead of just 5 times?
def print_triangle(rows)
top = (1..rows).to_a
i = 1
while i <= rows
top.map { |x| i.times { print "*" } }
puts "\n"
i += 1
end
end