Skip to content

Instantly share code, notes, and snippets.

@andrewstevenson
Created September 11, 2016 15:35
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 andrewstevenson/41db8a69633dd64014c31dcb2ba2c458 to your computer and use it in GitHub Desktop.
Save andrewstevenson/41db8a69633dd64014c31dcb2ba2c458 to your computer and use it in GitHub Desktop.
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