JavaScript - Too Much Recursion
hello every one , i'm new and i hoped u could help me with my code
I keep getting the same message "too much recursion" and i really don't know what is wrong , my friend and i codded the same way ,but it works for her not for me , here is the code : [merge sort algorithm] Code: var A=[2,999,45,23,17,879]; var B=[]; var C=[]; var i; var j; var k; var x=0; var mergesort_counter=0; var merge_counter=0; mergesort(A); //========================================================= //document.write( "<h2>mergesort</h2><p>", A, "</p>" ); function mergesort(A){ var n=A.length; mergesort_counter++; //count mergesort calls document.write( "<h2>mergesort</h2><p>", A, "</p>" ); var mid=Math.floor(n/2); if (n>1){ for (i=0;i<mid;i++){ B[i]=A[i];} for(j=mid;j<n;j++){ C[x]=A[j]; x++;} mergesort(B); mergesort(C); merge(B,C,A);} else document.write("the list is too short ");} function merge(B,C,A){ merge_counter++; //count merge calls i=0;k=0;j=0; while( i<B.length && j<C.length ){ if (B[i]<=C[j]){ A[k]=B[i]; i++;} else{ A[k]=C[j]; j++;}k++;} if(i==B.length) for (var l=j; l<C.length ; l++) {A[k]=C[l]; k++;} else for (var l=i; l<B.length ; l++) {A[k]=B[l]; k++;} document.write( "<h3>merge</h3><p>", A, "</p>" )} Similar Tutorialsthis code: Code: $(document).ready(function() { $('body').click(function(evt) { if(evt.target.nodeName === 'A' && $(evt.target).hasClass('cross-link')) { $('a[href=#2]').trigger('click'); } });}); gives me and error of "too much recursion" how can i solve this? Hi, can anyone tell me... Code: function Obj() { this.recursiveMethod=function () { //...how to invoke Obj.recursiveMethod from here? } } Gus Code: function checkifischild(draggedElement,destination) { $getid = $("#" + destination).attr("class"); var __temp = $getid.split(' '); console.log(__temp) for(i = 0;i < __temp.length; i++){//for the length of the classes if(__temp[i].match("child-of-")) {//check if its a child parent = __temp[i].substring(9);//get the parents node if(draggedElement == parent) { console.log('yes'); return false; } } } checkifischild(draggedElement,parent) } i have the following function basically what it does it gets 2 parameters node-23,node-17 for example it finds the classes of node-17 and splits them up ["child-of-node-16", "initialized", "ui-droppable", "expanded"] ["child-of-node-19", "initialized", "parent", "expanded", "ui-droppable"] ["child-of-node-23", "initialized", "parent", "expanded", "ui-droppable"] so i compare each time the first parameter along with the substring of the child-of and if they are the same its returns false now my problem is if i call the function just like this checkifischild(node-23,node-17) it works i get in the console yes for example if i do this tho if(checkifischild(node-23,node-17) == false) it fails :? any ideas will be appreciated thxxx Hey im having a problem recursively calling my function. What I want to do is to change MyImages[0-14] with a timeout between them. Here is my code. Code: function swapImage(i) { if(i < 15) { MyImages[i].src = "red_dot.gif"; setTimeout("swapImage(i+1)",500); } } The problem is that it will only change MyImages[0] and MyImages[1] Hello I am trying to create a family tree, parents / grandparents etc, of a single person... My database etc is already working but I cannot find any working examples that I can make sense of... Each of my records has a name, dob and id of each parent.... How can I get X generations from this.. I thought something like this might work.. GetParents For each parent GetParents And so on... But I have no idea how to put this into code... Any suggestions to put me on the right line would be greatly appreciated Thanks Hi, I am having trouble with a recursive function I created to list out the indexes and values of various nested objects. Code: var macros={ CTRL: { ALT: { ENTER: "<br />", P: "<p>.</p>", A: "<a href=\"\">.</a>", _1: "<h1>.</h1>", _2: "<h2>.</h2>", _3: "<h3>.</h3>", _4: "<h4>.</h4>", _5: "<h5>.</h5>", _6: "<h6>.</h6>" } } }; I want to print out the whole 'bread crumb trail' to each object, ie CTRL ALT 6: <h6>.</h6>, but at the moment my function prints out CTRL ALT twice for 'ENTER' and then never again. The function: Code: function printObj(obj) { for(i in obj) { var n=i.replace("_", ""); document.write(n); if(typeof obj[i]=="string") { document.write(":"); document.write(" "+obj[i].replace(/</g, "<").replace(/>/g, ">")); } else { document.write(n); } if(typeof obj[i]=="object") printObj(obj[i]); document.write("\n"); } } printObj(macros); The current output: Code: CTRLCTRLALTALTENTER: <br /> P: <p>.</p> A: <a href="">.</a> 1: <h1>.</h1> 2: <h2>.</h2> 3: <h3>.</h3> 4: <h4>.</h4> 5: <h5>.</h5> 6: <h6>.</h6> Any advice would be appreciated. Cheers, Gus Well, I clearly haven't the experience with javascript to understand why I can't do this: Code: function bubbleSortKernel(a, b) { if (b < 50) { swap(a, b); draw(); setTimeout("bubbleSortKernel(++a, ++b)", 200); } } where Code: swap(a, b) does just what it says: swaps the two elements in an array, and Code: draw() looks about like this: Code: function draw() { if (ctx != null) { ctx.clearRect(0, 0, width, height); for (var i = 0; i < rectangles.length; i++) { ctx.fillRect(x, rectangles[i][0], rectangles[i][1], rectangles[i][2]); } } } I'm newer to javascript that other things, and this seems perfectly legal to me. I'm looking for someone who knows more that I and can explain what I'm missing. I'm guessing my timeout doesn't really work like I think it does, but I've gotten so frustrated I can't see the forest for the trees. Any help or nudge is greatly appreciated. Thanks! well, when i do this fucntion: function scroll(){ window.scroll(0,60) } i get a javascript error: Error: too much recursion well, what is wrong? what does that mean? how do i fix it? thanks for any help |