Skip to content

Instantly share code, notes, and snippets.

View lunaroyster's full-sized avatar

Arnav Bansal lunaroyster

View GitHub Profile
var toTree = function(comments) {
comments.sort(function(x, y) {return -(x.degree-y.degree)}) //Sorts by degree, descending.
var treeDegree = comments[0].degree; //Max degree
var commentsByDegree = {};
for(var comment of comments) {
//Separates comments by degree.
comment.comments = [];
if(commentsByDegree.hasOwnProperty(comment.degree)) {
commentsByDegree[comment.degree].push(comment);
}