473,395 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Recursive function in java script

Expand|Select|Wrap|Line Numbers
  1.  
  2. function getsubroles(rolename1) 
  3. {
  4. var roles1=ctx.getAdminRoleProvider().findAdminRole(rolename1);
  5. var roles2=roles1.getAttributeMultiValue("CUSTOM10").iterator();
  6. if(roles2.hasNext())
  7. {
  8.  
  9.  while(roles2.hasNext())
  10.  {
  11.  
  12.    j++;
  13.    subrolesArr1[j]=roles2.next();
  14.    getsubroles(subroles[j]);
  15.  
  16. }
  17.  
  18. }
  19.  
  20. else return;
  21.  
  22. }
  23.  
I have written the above for a function to be called recursievly.
But I am not sure about the recursion of the function.
My confustion is on returning the functions .
Do i need to write only return to recurse the function or I have to write return <function name()>.
Jun 4 '08 #1
2 1618
vikas251074
198 100+
No! You need not write return <function_name> at the calling place.
Your calling portion of programme is correct.

Thanks and regards,
Vikas
Jun 4 '08 #2
rnd me
427 Expert 256MB
does your example work for you?

there are different ways of doing it, depending on your style.

check out this wiki article for more info.

for instance:
Expand|Select|Wrap|Line Numbers
  1.  
  2. function fact( n)
  3. {
  4.    if (n == 1) return 1;
  5.  return n * fact(n - 1);
  6. }
  7.  
  8. alert(fact(6))
  9.  
  10.  
Jun 4 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
2
by: LoserInYourFaceEngineer | last post by:
Hello All: I'm having trouble with a recursive function. The function is supposed to identify nested folders in a hierarchical folder structure. The function "searchForFolders()" is...
8
by: Ryan Stewart | last post by:
Putting the following code in a page seems to make it go into an infinite loop unless you give it a very simple node to work with. Either that or it's very very slow. I'm somewhat new to this,...
13
by: nobody | last post by:
Hello all, I've searched just about everything and although I can see that other people are having problems, but theirs don't seem to relate, so in a last ditch attempt, my posting! Script...
4
by: Nicolas Vigier | last post by:
Hello, I have in my python script a function that look like this : def my_function(arg1, arg2, opt1=0, opt2=1, opt3=42): if type(arg1) is ListType: for a in arg1: my_function(a, arg2,...
9
by: Bill Borg | last post by:
Hello, I call a function recursively to find an item that exists *anywhere* down the chain. Let's say I find it five layers deep. Now I've got what I need and want to break out of that whole...
9
by: Csaba Gabor | last post by:
Inside a function, I'd like to know the call stack. By this I mean that I'd like to know the function that called this one, that one's caller and so on. So I thought to do: <script...
1
by: Laura Huen | last post by:
I am just new to Java script. Can you help to write a recursive function: threeToThe(n) that computes pow(3,n). For example threeToThe(2) would return 9?
2
by: wgarner | last post by:
I am trying to implement a two-dimensional recursive formula, g(x,y). It is sort of like multiplication. g(x,y) = 0 if either x or y is 0. g(1, y) = y and g(x, 1) = x. Those are the base...
6
KevinADC
by: KevinADC | last post by:
This snippet of code provides several examples of programming techniques that can be applied to most programs. using hashes to create unique results static variable recursive function...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.