Created
October 2, 2018 22:44
-
-
Save AyoAlfonso/7c77f9ae40f6b99a9cd9503774b1cb2b to your computer and use it in GitHub Desktop.
A Function For Unfolding Comments on Firebase
This file contains hidden or 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
let rootCommentsCard = [] | |
let repliesCard = [] | |
function arrangeComments(comments){ | |
for (var commentId in comments) { | |
let parent = comments[commentId].parent | |
if (parent[0] == 'root') { | |
comments[commentId].commentId = commentId | |
comments[commentId].replies = [] | |
rootCommentsCard.push(comments[commentId]) | |
} else { | |
comments[commentId].commentId = commentId | |
repliesCard.push(comments[commentId]) | |
} | |
} | |
rootCommentsCard.map(card =>{ | |
repliesCard.forEach(reply=> { | |
if (reply.parent[0] == card.commentId) { | |
card.replies.push(reply) | |
} | |
}) | |
}) | |
} | |
arrangeComments(comments) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment