I have an an object I need to transform into a different format
The original:
{"module1":{"mod1":[{"hours":10},{"weeks":2},{"days":15}]},
"module2":{"mod2":[{"cars":1},{"cats":5},{"people":4}]},
}
the desired result :
{"module1":"/mod1/10/2/15","module2":"/mod2/1/5/4" }
Here is my attempt (sorry im still learning this)
function(newUrl){
var encodedUrl = {};
var tempString = "";
console.log(JSON.stringify(newUrl));
for (var p in newUrl) {
tempString = "/" + Object.keys(newUrl[p]);
for (var j in newUrl[p]){
_.each(newUrl[p][j], function(obj){
tempString += "/" + _.values(obj);
});
encodedUrl[p] = tempString;
console.log(encodedUrl);
}
}
}
So, I think i was able to make the string correctly. Hoever it only seems to be working the first time around. it's logging in a weird pattern
Object {module1: "/mod1/10/2/15"}
Object {module1: "/mod1///"}
Object {module1: "/mod1///", module2: "/mod2/1/5/4"}
I think i have something wrong in my logic parsing this, I cannot pinpoint it though. Would love a second pair of eyes to help. Thanks!