7 kyu

Do you know how to make Query String?

569 of 1,278isqua

Description:

Query string is a way to serialize object, which is used in HTTP requests. You may see it in URL:

codewars.com/kata/search/?q=querystring

The part q=querystring represents that parameter q has value querystring. Also sometimes querystring used in HTTP POST body:

POST /api/users
Content-Type: application/x-www-form-urlencoded

username=warrior&kyu=1&age=28

The string username=warrior&kyu=1&age=28 represents an entity (user in this example) with username equals warrior, kyu equals 1 and age equals 28. The entity may be represented as object:

{
  "username": "warrior",
  "kyu": 1,
  "age": 28
}

Sometimes there are more than one value for property:

{
  "name": "shirt",
  "colors": [ "white", "black" ]
}

Then it represents as repeated param:

name=shirt&colors=white&colors=black

So, your task is to write a function that convert an object to query string:

to_query_string({ "bar": [ 2, 3 ], "foo": 1 }) # => "bar=2&bar=3&foo=1"
toQueryString({ foo: 1, bar: [ 2, 3 ] }) // => "foo=1&bar=2&bar=3"
to_query_string({ "bar": [ 2, 3 ], "foo": 1 }) // => "bar=2&bar=3&foo=1"
to_query_string({ "bar": [ 2, 3 ], "foo": 1 }) # => "bar=2&bar=3&foo=1"

Next you may enjoy kata Objectify a URL Query String.

Note: require has been disabled.

Algorithms
Data Structures
Strings

Stats:

CreatedJun 27, 2017
PublishedJun 27, 2017
Warriors Trained2671
Total Skips33
Total Code Submissions8140
Total Times Completed1278
JavaScript Completions569
TypeScript Completions78
Python Completions610
Ruby Completions80
Crystal Completions3
Total Stars36
% of votes with a positive feedback rating86% of 271
Total "Very Satisfied" Votes212
Total "Somewhat Satisfied" Votes43
Total "Not Satisfied" Votes16
Total Rank Assessments10
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • isqua Avatar
  • GiacomoSorbi Avatar
  • matt c Avatar
  • Blind4Basics Avatar
  • Voile Avatar
Ad