Coding Challenge - #26: Query String Parser

Write a function parseQuery(queryString) that parses a URL query string (with or without a leading ?) into an object of key-value pairs. Decoded values should be properly unescaped (e.g., %20 or + becoming spaces).

function parseQuery(queryString) {
  // Your code here
}

Rules:

  • Must handle query strings starting with or without a leading ‘?’
  • Must decode percent-encoded characters and ‘+’ as spaces
  • Return an empty object if the input is empty or just ‘?’

Post your solution as a reply. Answer goes up in about a day.

The challenge seems straightforward, but what happens if a key appears multiple times?

The rules don’t specify if it should return the first value, the last, or an array of all values. That’s a common ambiguity in real-world parsing.