Last active
August 29, 2015 14:01
-
-
Save gko/1e06b20e92bacad303f6 to your computer and use it in GitHub Desktop.
"a.b.c.d" -> {a: {b: {c: "d"}}}
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 p(s) { | |
var a = s.split('.').reverse(), | |
_p = function(a, d, o) { | |
var i=o?0:1; | |
if(d>0) { | |
var t={}; t[a[i]]=o||a[0]; | |
return _p(a.slice(1+i), d-1-i, t); | |
} else return o; | |
}; | |
return _p(a, a.length); | |
} | |
console.log(p('a.b.c.d.e.f.g')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment