4 kyu

UriBuilder

1,567 of 1,678jhoffner

Description:

Create a basic UriBuilder object that will be used specifically to build query params on an existing URI. It should support a params property and a build method. It will handle the URL having pre-existing params that need to be managed. The URL must be properly encoded (i.e. "a b" should be encoded as "a%20b")

Examples of how the builder will be used:


var builder = new UriBuilder('http://www.codewars.com')
builder.params.page = 1
builder.params.language = 'javascript'

// new builder instance to demonstrate pre-existing params.
builder = new UriBuilder('http://www.codewars.com?page=1')

builder.params.page = 2
// should return 'http://www.codewars.com?page=2'
builder.build()

// if you delete params then they will disappear from the url string
delete builder.params.page

// should return 'http://www.codewars.com'
builder.build()

builder = new UriBuilder('http://www.codewars.com')
builder.params.page = 1
builder.params.language = 'javascript'

# should return 'http://www.codewars.com?page=1&language=javascript'
builder.build() 

# new builder instance to demonstrate pre-existing params.
builder = new UriBuilder('http://www.codewars.com?page=1')
builder.params.page = 2

# should return 'http://www.codewars.com?page=2'
builder.build()

# if you delete params then they will disappear from the url string
delete builder.params.page

# should return 'http://www.codewars.com'
builder.build()

Note: For extra style points you can have your solution handle array values as query parameters, however there are no tests that explicitly test for them.

Object-oriented Programming
Strings
Parsing
Algorithms

More By Author:

Check out these other kata created by jhoffner

Stats:

CreatedJul 23, 2013
PublishedJul 23, 2013
Warriors Trained3616
Total Skips1056
Total Code Submissions14793
Total Times Completed1678
JavaScript Completions1567
CoffeeScript Completions100
Total Stars110
% of votes with a positive feedback rating87% of 218
Total "Very Satisfied" Votes169
Total "Somewhat Satisfied" Votes43
Total "Not Satisfied" Votes6
Ad
Contributors
  • jhoffner Avatar
Ad