Skip to content

Instantly share code, notes, and snippets.

@bitsmanent
Last active September 24, 2016 09:02
Show Gist options
  • Select an option

  • Save bitsmanent/b960338109f41971b2c37f5b93a5abe0 to your computer and use it in GitHub Desktop.

Select an option

Save bitsmanent/b960338109f41971b2c37f5b93a5abe0 to your computer and use it in GitHub Desktop.
Build a hierarchic object. Used in collects().
function deepset(obj, hier, val, _i) {
var k;
if(!_i)
_i = 0;
k = hier[_i];
if(!hier[_i + 1]) {
if(obj[k] !== undefined) {
if(typeof obj[k] == "string")
obj[k] = [obj[k]];
obj[k].push(val);
}
else
obj[k] = val;
return;
}
if(!obj[k])
obj[k] = {};
deepset(obj[k], hier, val, _i + 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment