Last active
July 6, 2019 17:15
-
-
Save jamfromouterspace/dc901e150ee2c4c35a9957ca1ce0c062 to your computer and use it in GitHub Desktop.
A simple recursive function for flattening a tree of forum posts saved in MongoDB, preserving the correct order in which to display them (left order traversal). Used in notmoodle.com (app.js and thread.ejs).
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
var getPostPriority = async function(nodeRef, priority){ | |
var node = await Post.findById(nodeRef) | |
priority.push(node); | |
for(var i = 0; i < node.children.length; i++) | |
await getPostPriority(node.children[i], priority); | |
return priority; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment