80. implement your own URLSearchParams

JavaScript
Is this helpful ?

from all members: - accepted / - tried

When we want to extract parameters from query string, URLSearchParams could be very handy.

Can you implement MyURLSearchParams which works the same ?

const params = new MyURLSearchParams('?a=1&a=2&b=2')
params.get('a') // '1'
params.getAll('a') // ['1', '2']
params.get('b') // '2'
params.getAll('b') // ['2']


params.append('a', 3)
params.set('b', '3')
params.toString() // 'a=1&a=2&b=3&a=3'

There are a few methods on URLSearchParams, please implement them all.

Let's try to solve this problem within 20 mintues.

Discuss(8)