Skip to content

Instantly share code, notes, and snippets.

@pablq
Last active August 29, 2015 13:59
Show Gist options
  • Save pablq/10441993 to your computer and use it in GitHub Desktop.
Save pablq/10441993 to your computer and use it in GitHub Desktop.
// 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