Added method to flatten objects.

Now for tests.
Moved from CoffeeScript to JS