Write a program to transform the JSON provided in #Input into the one shown in #Output. Basically, each child should be placed in the children
array of its parent (as defined by the parent_id
).
Submit one solution using the language of your choice and one using Elixir. If you don't know Elixir yet, you will need to learn just enough for this challenge. Note that not being able to complete the Elixir implementation is okay, just send what you were able to write and explain what blocked you.
Keep track of the amount of hours you spend for each implementation and send them with your submission to thibault@omisego.co.
{"0":
[{"id": 10,
"title": "House",
"level": 0,
"children": [],
"parent_id": null}],
"1":
[{"id": 12,
"title": "Red Roof",
"level": 1,
"children": [],
"parent_id": 10},
{"id": 18,
"title": "Blue Roof",
"level": 1,
"children": [],
"parent_id": 10},
{"id": 13,
"title": "Wall",
"level": 1,
"children": [],
"parent_id": 10}],
"2":
[{"id": 17,
"title": "Blue Window",
"level": 2,
"children": [],
"parent_id": 12},
{"id": 16,
"title": "Door",
"level": 2,
"children": [],
"parent_id": 13},
{"id": 15,
"title": "Red Window",
"level": 2,
"children": [],
"parent_id": 12}]}
[{"id": 10,
"title": "House",
"level": 0,
"children":
[{"id": 12,
"title": "Red Roof",
"level": 1,
"children":
[{"id": 17,
"title": "Blue Window",
"level": 2,
"children": [],
"parent_id": 12},
{"id": 15,
"title": "Red Window",
"level": 2,
"children": [],
"parent_id": 12}],
"parent_id": 10},
{"id": 18,
"title": "Blue Roof",
"level": 1,
"children": [],
"parent_id": 10},
{"id": 13,
"title": "Wall",
"level": 1,
"children":
[{"id": 16,
"title": "Door",
"level": 2,
"children": [],
"parent_id": 13}],
"parent_id": 10}],
"parent_id": null}]