Just on Hacker news, John Resig contemplates transforming a query “foo=1&foo=2&foo=3&blah=a&blah=b” into one that looks like this: “foo=1,2,3&blah=a,b", https://johnresig.com/blog/search-and-dont-replace/. He claims "being 10 lines shorter than Mark’s solution".
Query strings consist of sequences of name-value pairs. Name-value pairs consist of a name and value, separated by =. names and values are possibly empty sequences of alphanumeric characters. Name-value pairs are separated by the & character in the sequence. Values are unique for each name.
10 lines shorter than Mark's solution is not enough.
- Read a query string.
- Combine name value pairs with equal name into a single name value pair, with values concatenated and separated by comma.
- Output the combined query string, with name-value pairs in the order the names are found from left to right in the query string.
This is code golf, the standard loopholes are closed.
Example Input and Output