Skip to content

Commit

Permalink
Finished all exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
jcarrharris committed Aug 21, 2013
1 parent aeba46f commit 9117a10
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Arrays/Exercise_Implement_Array_Flatten.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Array
def flatten
___
self.length.times {self.flatten!}
self
end
end

Expand Down
14 changes: 13 additions & 1 deletion Arrays/Exercise_Version_Sort.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
class Array
def version_sort
___
def to_array(s)
a = s.scan(/(\d+)([a-z]*)/).flatten
a.each_with_index.map {|e,i| i.even? ? e.to_i : e!="" ? e : i==a.length-1 ? (?a.ord-1).chr : (?z.ord+1).chr}
end

return self.sort do |a,b|
am, bm = to_array(a), to_array(b)
len = [am.length, bm.length].min
cmp = 0
am[0,len].zip(bm[0,len]).each {|pair| break if (cmp = (pair.first<=>pair.last)) != 0}
cmp
end
end
end

filenames = [
"foo-1.10.2.ext",
"foo-1.11.ext",
Expand Down
17 changes: 16 additions & 1 deletion Classes/Exercise_Baby_Got_Stacks.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
class Stack
___
def initialize(stack)
@stack = stack
end

def pop(*n)
@stack.pop(*n)
end

def push(items)
@stack.push(*items.reverse)
true
end

def to_a
@stack
end
end

stack = Stack.new([5, 6, 7, 8])
Expand Down
2 changes: 1 addition & 1 deletion Classes/Exercise_Getters_Setters.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Character
___ :name, :quote
attr_accessor :name, :quote
end

thorin = Character.new
Expand Down
15 changes: 14 additions & 1 deletion Classes/Exercise_Queue_Continuum.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
class Queue
___
def initialize(queue)
@queue = queue
end
def pop(*n)
@queue.shift(*n)
end

def push(items)
@queue.push(*items)
true
end

def to_a
@queue
end
end
queue = Queue.new([5, 6, 7, 8])

assert_equal queue.pop, 5
Expand Down
2 changes: 1 addition & 1 deletion Hashes/Exercise_The_Little_Hash_Key_that_Could.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def key_for_min_value(hash)
___
hash.key(hash.values.min)
end


Expand Down

0 comments on commit 9117a10

Please sign in to comment.