M
M
mimocrocodile2020-09-23 08:57:15
JavaScript
mimocrocodile, 2020-09-23 08:57:15

Recursive search in an array of objects?

Hello.

There is an array with objects, each of the objects is a comment record. Each object can have a nested object (reply to a comment). Each object has the same structure, each has the "Rating" property

Task: write a function that finds the required comment in the array by the given id and changes its rating (+1 or -1 depends on the second parameter in the function)

Tried to build a recursive search, but failed. Most likely, the algorithm was built incorrectly.

What could be the mistake, where did you make a mistake and what should be rewritten?

Sandbox attached: https://jsfiddle.net/gm2xz9bq/3/
Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kocherman, 2020-09-23
@mimocrocodile

Keep
https://jsfiddle.net/7w13bvhg/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question