Added JavaScript implementation