Implemented max length JS solution