Last active
August 29, 2015 13:59
-
-
Save pablq/10441993 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// wow this one killed me for a bit. now i should mention i have very little to no javascript experience... | |
// i got it though! | |
// getting the thing to not put a comma after the last element was the hardest part! | |
function solution(pairs) | |
{ | |
var size = 0, checksize = 1, s = "", key; | |
for (key in pairs) | |
{ | |
if (pairs.hasOwnProperty(key)) | |
{ | |
size++; | |
} | |
} | |
for (key in pairs) | |
{ | |
if (pairs.hasOwnProperty(key)) | |
{ | |
if(checksize < size) | |
{ | |
s = s + key + " = " + pairs[key] + ","; | |
} | |
else | |
{ | |
s = s + key + " = " + pairs[key]; | |
} | |
checksize++; | |
} | |
} | |
return s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment