Skip to content

Instantly share code, notes, and snippets.

@sarathsp06
Last active August 28, 2018 13:05
Show Gist options
  • Save sarathsp06/732c71f22aee26fa89975b9fb75d03dd to your computer and use it in GitHub Desktop.
Save sarathsp06/732c71f22aee26fa89975b9fb75d03dd to your computer and use it in GitHub Desktop.
Convert a string with dots('.') to a tree structure
var lst = function(array){return array.slice(-1);}
var head = function(array){return array.slice(0,-1);}
function CreateTree(key){
keys = key.split('.')
tags = {}
var last = lst(keys)
var hd = head(keys)
while(hd.length!==0){
tags[hd.join(".")] = last[0]
last = lst(hd)
hd = head(hd)
}
return tags
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment