/**
* Merges datasets of URL parameters with limited memory usage.
*
* @param {...string} params - Variable number of URL parameter strings (e.g., "param1=value1¶m2=value2").
* @returns {object} - An object containing the merged parameters.
*/
function mergeParams(...params) {
const merged = {}; // Initialize an empty object to store merged parameters
for (const param of params) {
if (param) {
const pairs = param.split('&'); // Split the parameter string into key-value pairs.
for (const pair of pairs) {
const [key, value] = pair.split('='); // Split each pair into key and value.
if (key) { // Ensure the key is not empty
merged[key] = value || true; // Assign value to key; default to true if no value is provided
}
}
}
}
return merged;
}
Add your comment