Javascript recursion example

Everyone loves(or should i say ‘gets intimidated by’?) Recursion. But it can be confusing to begin with. So here’s an example of recursion ( in javascript ) to show how recursion can be used to solve real problems in real projects 😉 . The code below is an altered code from one of my projects. Although its in javascript, the basic principle is same and can be easily reproduced in any other language of your choice.

Hope it helps..