MCPcopy Index your code
hub / github.com/dev-mastery/comments-api / nest

Function nest

src/use-cases/list-comments.js:14–28  ·  view source on GitHub ↗
(comments)

Source from the content-addressed store, hash-verified

12
13 // If this gets slow introduce caching.
14 function nest (comments) {
15 if (comments.length === 0) {
16 return comments
17 }
18 return comments.reduce((nested, comment) => {
19 comment.replies = comments.filter(
20 reply => reply.replyToId === comment.id
21 )
22 nest(comment.replies)
23 if (comment.replyToId == null) {
24 nested.push(comment)
25 }
26 return nested
27 }, [])
28 }
29 }
30}

Callers 1

makeListCommentsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected