This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BST = Struct.new(:data, :left, :right) do | |
def insert(new_data) | |
new_data > self.data ? input(:right, new_data) : input(:left, new_data) | |
end | |
def input(side, new_data) | |
self[side] ? self[side].insert(new_data) : self[side] = BST.new(new_data) | |
end | |
def each(&block) | |
self.left.each(&block) if self.left | |
yield self.data | |
self.right.each(&block) if self.right | |
end | |
end |
I thought a Struct was warranted to avoid having to use
self.send
; this way, I could do self[side] using the built-in Struct []
method.We spent a lot of time going over forms and associations in Sinatra, and working on some assignments dealing with complex associations. In short, we put together a web app with virtual houses that give out candy to trick-or-treaters, i.e. users who have input a name and age. Each user has a bucket that holds all the candy, and you can view all houses, or a particular house, view your bucket, and eat your candy - which may get you sick if you eat too much!
In the evening, we had a meetup; my favorite project was by Arielle Sullivan and Chris Guthrie, who put together a web app that finds the worst (in terms of health department violations) restaurants in any zip code in New York City. Apparently, the Subway a lot of people go to during lunch is pretty awful. Oops.
Skills developed: Binary search trees, forms and complex associations in Sinatra
No comments:
Post a Comment