Javier Valderrama
1 min readSep 13, 2019

--

Whilst the solution is clear, there’s a gotcha to take in consideration: JS accept circular references, hence you might end up on a stack overflow due to the recursion, or in an infinite loop if you avoid the recursion.

One solution, that comes at a cost ( memory ), might be using memoization.

Thanks for sharing your knowledge

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Javier Valderrama
Javier Valderrama

Written by Javier Valderrama

Engineering manager, Lead Software engineer, passionate educator and community evangelist.

No responses yet

Write a response