A product listing page keeps its filters in the URL, like ?color=red&size=m&size=l&q=summer+dress. Write parseQuery(query) that turns such a string into an object.
? is ignored. Pairs are separated by &, and empty pairs are skipped.=. A pair without = has the value "". Pairs with an empty key are skipped.+ means a space, and %XX escapes are decoded (use decodeURIComponent after replacing +).Input: query = "?color=red&size=m&size=l&q=summer+dress" Output: {"color":"red","size":["m","l"],"q":"summer dress"}
size appears twice, so it becomes an array; + becomes a space.
Input: query = "sort&page=2" Output: {"sort":"","page":"2"}
sort has no =, so its value is empty.
0 <= query.length <= 10^4% escapes in the input are valid.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #627 Read a Query String. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.