1. /**
  2. * Merges datasets of URL parameters with limited memory usage.
  3. *
  4. * @param {...string} params - Variable number of URL parameter strings (e.g., "param1=value1&param2=value2").
  5. * @returns {object} - An object containing the merged parameters.
  6. */
  7. function mergeParams(...params) {
  8. const merged = {}; // Initialize an empty object to store merged parameters
  9. for (const param of params) {
  10. if (param) {
  11. const pairs = param.split('&'); // Split the parameter string into key-value pairs.
  12. for (const pair of pairs) {
  13. const [key, value] = pair.split('='); // Split each pair into key and value.
  14. if (key) { // Ensure the key is not empty
  15. merged[key] = value || true; // Assign value to key; default to true if no value is provided
  16. }
  17. }
  18. }
  19. }
  20. return merged;
  21. }

Add your comment