Code Lab

Mode entretien. Minuteur de 5 min, sans indices ni autocomplétion

URL parameters

FacileJSON and data5 min

Write a function parseQuery(query) that turns a URL parameter string such as 'a=b&c=d' into an object { a: 'b', c: 'd' }. Pairs are separated by &, and a key and its value are separated by =. The values stay strings.

Exemples

parseQuery('page=2&sort=price')

Renvoie { page: '2', sort: 'price' }

parseQuery('')

Renvoie {}

An empty string gives an empty object.

Posé chez Airbnb · Source

Chargement de l'éditeur...
  1. EntréeparseQuery('a=b&c=d')
    Attendu{ a: 'b', c: 'd' }
  2. EntréeparseQuery('page=2&sort=price')
    Attendu{ page: '2', sort: 'price' }
  3. EntréeparseQuery('')
    Attendu{}

Les tests cachés se lancent à la soumission