Proof of Work · Challenge
Turn ?a=1&a=2 into data, and data back into a URL.
about 25 min · 7 required tests · in the browser
What is recorded: when you save, your Result page shows your code, which tests passed, how many times you ran the tests, how many versions you tried, the time from first run to save, and the largest jump in code between runs. Anyone with the link can see it. The suggested time is not enforced.
Filters, search boxes, and pagination all live in the URL. Write the two functions that move between a query string and a plain object. Do not reach for URLSearchParams: the point is to handle the details yourself.
Implement parseQuery(text) and stringifyQuery(obj).
parseQuery returns an object of strings:
? is allowed and ignored. An empty string gives {}.+ in a key or value means a space, but %2B means a real plus sign.a= and a bare a both give the empty string "".& characters are ignored.stringifyQuery is the reverse:
encodeURIComponent.key=value pair per item, in order.&. There is no leading ?.parseQuery("?tag=js&tag=css&q=hello+world&page=")
// { tag: ["js", "css"], q: "hello world", page: "" }
stringifyQuery({ tag: ["js", "css"], q: "a&b" })
// "tag=js&tag=css&q=a%26b"Write two top-level functions named parseQuery and stringifyQuery. Do not use export or module.exports.
Press Esc, then Tab, to leave the editor.
⌘ / Ctrl + Enter runs the tests
Hiring developers? See how teams use this.
Graded on
0/7
Other builds