Created
September 11, 2016 15:35
-
-
Save andrewstevenson/41db8a69633dd64014c31dcb2ba2c458 to your computer and use it in GitHub Desktop.
This file contains 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
return pb.mapValues( | |
function(value) | |
function flatten (acc, element, parentId) | |
local id = #acc + 1 | |
acc[id] = { value = element.value, id = id, parent = parentId } | |
for i, child in ipairs(element.children) do | |
flatten(acc, child, id) | |
end | |
end | |
local flatElements = {} | |
for i, element in ipairs(value.elements) do | |
flatten(flatElements, element, 0) | |
end | |
value.elements = flatElements | |
return value | |
end | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment