A discussion widget stores a thread as one comment object { id, replies }, where replies is an array of comment objects with the same shape. Replies can have replies of their own, as deep as people keep answering.
Write countComments(thread) that returns how many comments the thread holds, counting the top comment itself.
Input: thread = {"id":1,"replies":[{"id":2,"replies":[]},{"id":3,"replies":[{"id":4,"replies":[]}]}]} Output: 4
Comment 1 has replies 2 and 3, and 3 has reply 4: four comments.
Input: thread = {"id":7,"replies":[]} Output: 1
A comment with no replies is a thread of one.
1 and 1000 comments.100 levels deep.replies array (it may be empty).Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #3 Count Every Reply. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.