Are we sure this is a recursive approach? I feel like this is an iterative solution as we just run a block until a condition is met. The function is not called multiple times.
function dRoot(num) { const parts = num.toString().split(""); const sum = parts.reduce((aggr,part) => parseInt(part) + parseInt(aggr)); if(sum > 9) return dRoot(sum); return sum; }
I think this qualifies as recursive. But the iterative approach in the article is much more performant I think. Nice article.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Are we sure this is a recursive approach? I feel like this is an iterative solution as we just run a block until a condition is met. The function is not called multiple times.
I think this qualifies as recursive. But the iterative approach in the article is much more performant I think. Nice article.