-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrichOutput.js
More file actions
37 lines (30 loc) · 852 Bytes
/
richOutput.js
File metadata and controls
37 lines (30 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
Random Code Showcase
Jujhar Singh
Nov/9/2014
-------------
Task
Write a function that takes an key-value dictionary and returns the output in the following format: ?key=value1&key2=value2&key3=ba
*/
var parseMe= {key:"value1",key2:"value2",key3:"ba"}
var keys = Object.keys(parseMe)
// Change format of dictionary to ?key=value1&key2=value2&key3=ba format
function laParser() {
// always first character
var r = "?"
// separting character
var seperata = "&"
for (var keya in keys) {
var item = keys[keya]
r += keys[keya]+"="+parseMe[item]+seperata
}
// deleate trailing seperata variable
r = r.substring(0, r.length - 1);
console.log("r is: "+r)
return r
}
laParser()
// Test to see if match
var output = "?key=value1&key2=value2&key3=ba"
console.log(laParser()==output)
console.log("----");