Skip to content

Instantly share code, notes, and snippets.

@meltingice
Last active May 24, 2017 15:31
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 meltingice/a8090f51f14cf5c57ddd3cbfc244fe34 to your computer and use it in GitHub Desktop.
Save meltingice/a8090f51f14cf5c57ddd3cbfc244fe34 to your computer and use it in GitHub Desktop.
# We create an index to store all of the comments in the tree,
# indexed by ID. This lets us quickly build out the comment structure
# as we iterate over each comment.
node_index = ActiveSupport::OrderedHash.new
nodes.each do |node|
node_index[node.id] = {
node: node,
parent: nil,
reply_to: nil,
children: []
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment