Updated .js version of the solution