Added JavaScript implementationg