baseUrl.js
function correctQuestionMarkAndAnd(url) {
	var baseURL = url;

	// Remove && mistake
	baseURL = baseURL.replace(new RegExp('&&', 'g'), '&');

	// Ends width ?
	if (new RegExp('[\?]$').test(baseURL)) {
		// Do nothing
	} else {
		// Does not end on ?
		// Contains ?
		if (baseURL.includes('?')) {
			// Ends width &
			if (new RegExp('[\&]$').test(baseURL)) {
				// Do nothing
			} else {
				// Does not end on &
				// Add &
				baseURL += '&';
			}

		} else {
			// Does not contain on ?

			// Count of &
			var countOfAnd = baseURL.split('&').length - 1;

			// Ends with &
			if (new RegExp('[\&]$').test(baseURL)) {

				if (countOfAnd === 1) {
					// Remove &
					baseURL = baseURL.slice(0, -1);
					// Add ?
					baseURL += '?';
				} else {
					// Replace first & with ?
					baseURL = baseURL.replace('&', '?');
				}

			} else {
				// Does not contain on ? ends not on &

				// Contains one or more &
				if (countOfAnd > 1) {

					// Replace first & with ?
					baseURL = baseURL.replace('&', '?');

					// Add &
					baseURL += '&';
				} else {
					// Does not contain &
					// Add ?
					baseURL += '?';
				}

			}

		}
	}

	return baseURL;
}
function correctQuestionMarkAndAnd(url) {
	var baseURL = url;

	// Remove && mistake
	baseURL = baseURL.replace(new RegExp('&&', 'g'), '&');

	// Ends width ?
	if (new RegExp('[\?]$').test(baseURL)) {
		// Do nothing
	} else {
		// Does not end on ?
		// Contains ?
		if (baseURL.includes('?')) {
			// Ends width &
			if (new RegExp('[\&]$').test(baseURL)) {
				// Do nothing
			} else {
				// Does not end on &
				// Add &
				baseURL += '&';
			}

		} else {
			// Does not contain on ?

			// Count of &
			var countOfAnd = baseURL.split('&').length - 1;

			// Ends with &
			if (new RegExp('[\&]$').test(baseURL)) {

				if (countOfAnd === 1) {
					// Remove &
					baseURL = baseURL.slice(0, -1);
					// Add ?
					baseURL += '?';
				} else {
					// Replace first & with ?
					baseURL = baseURL.replace('&', '?');
				}

			} else {
				// Does not contain on ? ends not on &

				// Contains one or more &
				if (countOfAnd > 1) {

					// Replace first & with ?
					baseURL = baseURL.replace('&', '?');

					// Add &
					baseURL += '&';
				} else {
					// Does not contain &
					// Add ?
					baseURL += '?';
				}

			}

		}
	}

	return baseURL;
}
function correctQuestionMarkAndAnd ( url ) { var baseURL = url ; // Remove && mistake baseURL = baseURL . replace ( new RegExp ( '&&' , 'g' ) , '&' ) ; // Ends width ? if ( new RegExp ( '[\?]$' ) . test ( baseURL ) ) { // Do nothing } else { // Does not end on ? // Contains ? if ( baseURL . includes ( '?' ) ) { // Ends width & if ( new RegExp ( '[\&]$' ) . test ( baseURL ) ) { // Do nothing } else { // Does not end on & // Add & baseURL += '&' ; } } else { // Does not contain on ? // Count of & var countOfAnd = baseURL . split ( '&' ) . length - 1 ; // Ends with & if ( new RegExp ( '[\&]$' ) . test ( baseURL ) ) { if ( countOfAnd === 1 ) { // Remove & baseURL = baseURL . slice ( 0 , - 1 ) ; // Add ? baseURL += '?' ; } else { // Replace first & with ? baseURL = baseURL . replace ( '&' , '?' ) ; } } else { // Does not contain on ? ends not on & // Contains one or more & if ( countOfAnd > 1 ) { // Replace first & with ? baseURL = baseURL . replace ( '&' , '?' ) ; // Add & baseURL += '&' ; } else { // Does not contain & // Add ? baseURL += '?' ; } } } } return baseURL ; }
Correct mistakes with the characters '?' and '&'.

@param {string}
url URL with mistakes with the characters '?' and '&'.
@returns {string} URL without mistakes with the characters '?' and '&'.
Correct mistakes with the characters ? and & .