Skip to content

Instantly share code, notes, and snippets.

@ukazap
Last active November 10, 2017 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ukazap/af16148057d756289ab48e019c875cc8 to your computer and use it in GitHub Desktop.
Save ukazap/af16148057d756289ab48e019c875cc8 to your computer and use it in GitHub Desktop.
Write a function that take source and convert to target.
let source = [
{
name: "Account A"
},
{
name: "Account B"
},
{
name: "Account C"
},
{
name: "Account D",
parent: "Account C"
},
{
name: "Account E",
parent: "Account C"
},
{
name: "Account F",
parent: "Account E"
},
{
name: "Account G",
parent: "Account F"
},
]
let target = [
{
name: "Account A"
},
{
name: "Account B"
},
{
name: "Account C",
children: [
{
name: "Account D",
},
{
name: "Account E",
children: [
{
name: "Account F",
children: [
{
name: "Account G"
},
]
},
]
},
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment