Added jasmine tests and factored out javascript functions to new file