Last active
September 24, 2016 09:02
-
-
Save bitsmanent/b960338109f41971b2c37f5b93a5abe0 to your computer and use it in GitHub Desktop.
Build a hierarchic object. Used in collects().
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
| 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