I have many levels of nested comments inside my commentsArray
(This is pulled in from an API and cannot be changed)
commentsArray = [
{
author: "jeff"
replies: [
{
author: "jeff"
replies: [
{
author: "simon"
}
]
},
{
author: "simon"
}
]
},
{
author: "simon"
}
]
I also have a recursive function, dialogueParse, that calls itself if the object in question has “replies“
dialogueParse = (comment) ->
for child in comment
if child.author is "simon"
console.log "Simon was found.."
if child.replies
dialogueParse child
However, this code doesn’t seem to work correctly. After I call the function initially:
dialogueParse commentsArray
..for some reason, only the one located on the first level (at the end of the array) is found.
“simon” is listed as an author in 3 different places.
I’ve been working on this for several hours and getting nowhere. Any help is more than appreciated! 🙂
Shouldn’t you be passing
child.repliesas the argument in the recursion?As in: