JavaScript: Query string builder

Last update: 16 Oct 23:20
1
Student
100%
Completion rate

Query String is a part of the webpage address that contains constants and their values. It starts after the question mark and goes to the end of the address. Example:

# query string: page=5
https://ru.hexlet.io/blog?page=5

If there are several parameters, they are separated by an ampersand &:

# query string: page=5&per=10
https://ru.hexlet.io/blog?per=10&page=5

buildQueryString.js

Implement and export as default a function that takes a list of parameters and generates a query string from those parameters:

import bqs from '../buildQueryString.js';

bqs({ per: 10, page: 1 });
// page=1&per=10
bqs({ param: 'all', param1: true });
// param=all&param1=true

The parameter names in the output string must be in alphabetical order (i.e. they must be sorted).

For full access to the challenge you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests