how to make recursive function in javascript

Solutions on MaxInterview for how to make recursive function in javascript by the best coders in the world

showing results for - "how to make recursive function in javascript"
David
24 Jan 2020
1// Basic Recursive function
2// It works in all languages but lets try with C
3
4// lets make a greedy strlen
5
6int my_recursive_strlen(int index, char *str) // note that index must be set at 0 to work in this case
7{
8  if (str[index] == '\0')
9    return index + 1;
10  else
11    return my_recursive_strlen(index++); // i send index + 1 to next function call
12  // this increment index in our recursive stack
13}
14
15void main(void)
16{
17  printf("length of Bonjour = %d\n", my_recursive_strlen(0, "bonjour"));
18}
19
20//output : length of Bonjour = 7
21
22// Recursive functions are greedy and should be used in only special cases who need it
23// or who can handle it.
24
25// a function become recursive if she calls herself in stack
Juana
27 Jun 2020
1tagnina
2
similar questions