Recursion (Javascript) - does not exit recursion out of “IF” statement





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am learning recursion in Javascript and here's what I got so far. This function traverses the tree and finds an object with the matching name propertity. As the start needs to be set as the root, I created a recursion to use the root as the starting point.



The first if statement in the for loop halfway should return the match. I've debugged pieces of it in the console so I know that the return is not working for whatever reason that I am not aware of (any insight would be great for learning purposes!).



The set console logs as I expect it to, the boolean check shows that a match does happen, but still getting undefined at the end!



findInTree(name) {
let start = this.first(); //root object of the tree

function findName (start, name) {
if (start.name === name) {
return start;
} else {
for (let set of start.offspring) {
if (set.name === name) {
console.log(set); // returns the correct set!
console.log(set.name === name) //returns true;
return set;
} else {
findName(set, name);
}
}
}
}
return findName(start, name);
}
// returns undefined...









share|improve this question































    0















    I am learning recursion in Javascript and here's what I got so far. This function traverses the tree and finds an object with the matching name propertity. As the start needs to be set as the root, I created a recursion to use the root as the starting point.



    The first if statement in the for loop halfway should return the match. I've debugged pieces of it in the console so I know that the return is not working for whatever reason that I am not aware of (any insight would be great for learning purposes!).



    The set console logs as I expect it to, the boolean check shows that a match does happen, but still getting undefined at the end!



    findInTree(name) {
    let start = this.first(); //root object of the tree

    function findName (start, name) {
    if (start.name === name) {
    return start;
    } else {
    for (let set of start.offspring) {
    if (set.name === name) {
    console.log(set); // returns the correct set!
    console.log(set.name === name) //returns true;
    return set;
    } else {
    findName(set, name);
    }
    }
    }
    }
    return findName(start, name);
    }
    // returns undefined...









    share|improve this question



























      0












      0








      0








      I am learning recursion in Javascript and here's what I got so far. This function traverses the tree and finds an object with the matching name propertity. As the start needs to be set as the root, I created a recursion to use the root as the starting point.



      The first if statement in the for loop halfway should return the match. I've debugged pieces of it in the console so I know that the return is not working for whatever reason that I am not aware of (any insight would be great for learning purposes!).



      The set console logs as I expect it to, the boolean check shows that a match does happen, but still getting undefined at the end!



      findInTree(name) {
      let start = this.first(); //root object of the tree

      function findName (start, name) {
      if (start.name === name) {
      return start;
      } else {
      for (let set of start.offspring) {
      if (set.name === name) {
      console.log(set); // returns the correct set!
      console.log(set.name === name) //returns true;
      return set;
      } else {
      findName(set, name);
      }
      }
      }
      }
      return findName(start, name);
      }
      // returns undefined...









      share|improve this question
















      I am learning recursion in Javascript and here's what I got so far. This function traverses the tree and finds an object with the matching name propertity. As the start needs to be set as the root, I created a recursion to use the root as the starting point.



      The first if statement in the for loop halfway should return the match. I've debugged pieces of it in the console so I know that the return is not working for whatever reason that I am not aware of (any insight would be great for learning purposes!).



      The set console logs as I expect it to, the boolean check shows that a match does happen, but still getting undefined at the end!



      findInTree(name) {
      let start = this.first(); //root object of the tree

      function findName (start, name) {
      if (start.name === name) {
      return start;
      } else {
      for (let set of start.offspring) {
      if (set.name === name) {
      console.log(set); // returns the correct set!
      console.log(set.name === name) //returns true;
      return set;
      } else {
      findName(set, name);
      }
      }
      }
      }
      return findName(start, name);
      }
      // returns undefined...






      javascript recursion tree






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 3:14







      Elbert Bae

















      asked Nov 22 '18 at 3:10









      Elbert BaeElbert Bae

      33




      33
























          2 Answers
          2






          active

          oldest

          votes


















          0














          You only want to return from your loop if the recursion found what you're looking for. Otherwise you want to keep looping. You can test the result and decide whether to return:






          let obj = {
          first: {
          name: "test",
          offspring:[
          {name: "test1", offspring:},
          {name: "test2", offspring:[{name:"test21", offspring:}]},
          {name: "test3", offspring:[
          {name: "test31", offspring:}
          ]},
          ]
          },
          findInTree(name) {
          let start = this.first; //root object of the tree

          function findName (start, name) {
          if (start.name === name) {
          return start;
          } else {
          for (let set of start.offspring) {
          if (set.name === name) {
          console.log(set); // returns the correct set!
          console.log(set.name === name) //returns true;
          return set;
          } else {
          let found = findName(set, name); // only return if you've found
          if (found) return found // what you're looking for
          }
          }
          }
          }
          return findName(start, name);
          }
          }
          console.log(obj.findInTree("test31"))








          share|improve this answer
























          • Hmm... I think I kind of get it, but just for clarification, is there a reason why the return doesn't happen in the if statement "(set.name === name)"? My understanding was that if one of the recursions found a match, they would exit the loop and return the match using the "if/else". Is there a reason why this isn't the case? And also thank you for taking the time to review the code, I'll definitely look into it in detail for a better understanding.

            – Elbert Bae
            Nov 22 '18 at 3:46













          • So if you trace it though the tree above what happens is it calls findName() on the first offspring where the name doesn't exit. So that function doesn't return start because the condition doesn't match, and there's no children so it never runs the loop. The result is that it returns undefined. And returning from a for loop stops the loop and returns from the function before you get a chance to loop to the one containing what you want.

            – Mark Meyer
            Nov 22 '18 at 3:51











          • Oh! I see it now, wow. Thanks so much for the explanation Mark! Placement of the return, I'll keep an eye out for that moving forward.

            – Elbert Bae
            Nov 22 '18 at 4:07



















          0














          Do you think this will work? Move the recursion call out of the for loop. only if the match is not found in the for loop, you call the function findName. If possible, can you put your code in jsfiddle or somewhere so that I can take a look.



              findInTree(name) {
          let start = this.first(); //root object of the tree

          function findName (start, name) {
          if (start.name === name) {
          return start;
          } else {

          for (let set of start.offspring) {
          if (set.name === name) {
          console.log(set); // returns the correct set!
          console.log(set.name === name) //returns true;
          return set;
          }
          }
          return findName(set, name); //if the match is not found in the forloop, we call findname

          }
          }
          return findName(start, name);
          }





          share|improve this answer
























          • Just did a test run and unfortunately doesn't seem to work. Here's the jsfiddle link ! jsfiddle.net/4g6r5bz7

            – Elbert Bae
            Nov 22 '18 at 3:54













          • Most of your code looks good. I think you just need to add this to check whether match is undefined or not. let matchFound = findName(set, name); if(matchFound) return matchFound; I just saw that from the previous reply that you have already found the solution. Good to know.

            – Bala
            Nov 22 '18 at 4:23













          • Thank you for reviewing it! Yes, been looking into it to get a better understanding of how the matches take place in recursions, brushing up on how functions and loops react to returns!

            – Elbert Bae
            Nov 22 '18 at 4:34












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423323%2frecursion-javascript-does-not-exit-recursion-out-of-if-statement%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You only want to return from your loop if the recursion found what you're looking for. Otherwise you want to keep looping. You can test the result and decide whether to return:






          let obj = {
          first: {
          name: "test",
          offspring:[
          {name: "test1", offspring:},
          {name: "test2", offspring:[{name:"test21", offspring:}]},
          {name: "test3", offspring:[
          {name: "test31", offspring:}
          ]},
          ]
          },
          findInTree(name) {
          let start = this.first; //root object of the tree

          function findName (start, name) {
          if (start.name === name) {
          return start;
          } else {
          for (let set of start.offspring) {
          if (set.name === name) {
          console.log(set); // returns the correct set!
          console.log(set.name === name) //returns true;
          return set;
          } else {
          let found = findName(set, name); // only return if you've found
          if (found) return found // what you're looking for
          }
          }
          }
          }
          return findName(start, name);
          }
          }
          console.log(obj.findInTree("test31"))








          share|improve this answer
























          • Hmm... I think I kind of get it, but just for clarification, is there a reason why the return doesn't happen in the if statement "(set.name === name)"? My understanding was that if one of the recursions found a match, they would exit the loop and return the match using the "if/else". Is there a reason why this isn't the case? And also thank you for taking the time to review the code, I'll definitely look into it in detail for a better understanding.

            – Elbert Bae
            Nov 22 '18 at 3:46













          • So if you trace it though the tree above what happens is it calls findName() on the first offspring where the name doesn't exit. So that function doesn't return start because the condition doesn't match, and there's no children so it never runs the loop. The result is that it returns undefined. And returning from a for loop stops the loop and returns from the function before you get a chance to loop to the one containing what you want.

            – Mark Meyer
            Nov 22 '18 at 3:51











          • Oh! I see it now, wow. Thanks so much for the explanation Mark! Placement of the return, I'll keep an eye out for that moving forward.

            – Elbert Bae
            Nov 22 '18 at 4:07
















          0














          You only want to return from your loop if the recursion found what you're looking for. Otherwise you want to keep looping. You can test the result and decide whether to return:






          let obj = {
          first: {
          name: "test",
          offspring:[
          {name: "test1", offspring:},
          {name: "test2", offspring:[{name:"test21", offspring:}]},
          {name: "test3", offspring:[
          {name: "test31", offspring:}
          ]},
          ]
          },
          findInTree(name) {
          let start = this.first; //root object of the tree

          function findName (start, name) {
          if (start.name === name) {
          return start;
          } else {
          for (let set of start.offspring) {
          if (set.name === name) {
          console.log(set); // returns the correct set!
          console.log(set.name === name) //returns true;
          return set;
          } else {
          let found = findName(set, name); // only return if you've found
          if (found) return found // what you're looking for
          }
          }
          }
          }
          return findName(start, name);
          }
          }
          console.log(obj.findInTree("test31"))








          share|improve this answer
























          • Hmm... I think I kind of get it, but just for clarification, is there a reason why the return doesn't happen in the if statement "(set.name === name)"? My understanding was that if one of the recursions found a match, they would exit the loop and return the match using the "if/else". Is there a reason why this isn't the case? And also thank you for taking the time to review the code, I'll definitely look into it in detail for a better understanding.

            – Elbert Bae
            Nov 22 '18 at 3:46













          • So if you trace it though the tree above what happens is it calls findName() on the first offspring where the name doesn't exit. So that function doesn't return start because the condition doesn't match, and there's no children so it never runs the loop. The result is that it returns undefined. And returning from a for loop stops the loop and returns from the function before you get a chance to loop to the one containing what you want.

            – Mark Meyer
            Nov 22 '18 at 3:51











          • Oh! I see it now, wow. Thanks so much for the explanation Mark! Placement of the return, I'll keep an eye out for that moving forward.

            – Elbert Bae
            Nov 22 '18 at 4:07














          0












          0








          0







          You only want to return from your loop if the recursion found what you're looking for. Otherwise you want to keep looping. You can test the result and decide whether to return:






          let obj = {
          first: {
          name: "test",
          offspring:[
          {name: "test1", offspring:},
          {name: "test2", offspring:[{name:"test21", offspring:}]},
          {name: "test3", offspring:[
          {name: "test31", offspring:}
          ]},
          ]
          },
          findInTree(name) {
          let start = this.first; //root object of the tree

          function findName (start, name) {
          if (start.name === name) {
          return start;
          } else {
          for (let set of start.offspring) {
          if (set.name === name) {
          console.log(set); // returns the correct set!
          console.log(set.name === name) //returns true;
          return set;
          } else {
          let found = findName(set, name); // only return if you've found
          if (found) return found // what you're looking for
          }
          }
          }
          }
          return findName(start, name);
          }
          }
          console.log(obj.findInTree("test31"))








          share|improve this answer













          You only want to return from your loop if the recursion found what you're looking for. Otherwise you want to keep looping. You can test the result and decide whether to return:






          let obj = {
          first: {
          name: "test",
          offspring:[
          {name: "test1", offspring:},
          {name: "test2", offspring:[{name:"test21", offspring:}]},
          {name: "test3", offspring:[
          {name: "test31", offspring:}
          ]},
          ]
          },
          findInTree(name) {
          let start = this.first; //root object of the tree

          function findName (start, name) {
          if (start.name === name) {
          return start;
          } else {
          for (let set of start.offspring) {
          if (set.name === name) {
          console.log(set); // returns the correct set!
          console.log(set.name === name) //returns true;
          return set;
          } else {
          let found = findName(set, name); // only return if you've found
          if (found) return found // what you're looking for
          }
          }
          }
          }
          return findName(start, name);
          }
          }
          console.log(obj.findInTree("test31"))








          let obj = {
          first: {
          name: "test",
          offspring:[
          {name: "test1", offspring:},
          {name: "test2", offspring:[{name:"test21", offspring:}]},
          {name: "test3", offspring:[
          {name: "test31", offspring:}
          ]},
          ]
          },
          findInTree(name) {
          let start = this.first; //root object of the tree

          function findName (start, name) {
          if (start.name === name) {
          return start;
          } else {
          for (let set of start.offspring) {
          if (set.name === name) {
          console.log(set); // returns the correct set!
          console.log(set.name === name) //returns true;
          return set;
          } else {
          let found = findName(set, name); // only return if you've found
          if (found) return found // what you're looking for
          }
          }
          }
          }
          return findName(start, name);
          }
          }
          console.log(obj.findInTree("test31"))





          let obj = {
          first: {
          name: "test",
          offspring:[
          {name: "test1", offspring:},
          {name: "test2", offspring:[{name:"test21", offspring:}]},
          {name: "test3", offspring:[
          {name: "test31", offspring:}
          ]},
          ]
          },
          findInTree(name) {
          let start = this.first; //root object of the tree

          function findName (start, name) {
          if (start.name === name) {
          return start;
          } else {
          for (let set of start.offspring) {
          if (set.name === name) {
          console.log(set); // returns the correct set!
          console.log(set.name === name) //returns true;
          return set;
          } else {
          let found = findName(set, name); // only return if you've found
          if (found) return found // what you're looking for
          }
          }
          }
          }
          return findName(start, name);
          }
          }
          console.log(obj.findInTree("test31"))






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 3:31









          Mark MeyerMark Meyer

          40.7k33564




          40.7k33564













          • Hmm... I think I kind of get it, but just for clarification, is there a reason why the return doesn't happen in the if statement "(set.name === name)"? My understanding was that if one of the recursions found a match, they would exit the loop and return the match using the "if/else". Is there a reason why this isn't the case? And also thank you for taking the time to review the code, I'll definitely look into it in detail for a better understanding.

            – Elbert Bae
            Nov 22 '18 at 3:46













          • So if you trace it though the tree above what happens is it calls findName() on the first offspring where the name doesn't exit. So that function doesn't return start because the condition doesn't match, and there's no children so it never runs the loop. The result is that it returns undefined. And returning from a for loop stops the loop and returns from the function before you get a chance to loop to the one containing what you want.

            – Mark Meyer
            Nov 22 '18 at 3:51











          • Oh! I see it now, wow. Thanks so much for the explanation Mark! Placement of the return, I'll keep an eye out for that moving forward.

            – Elbert Bae
            Nov 22 '18 at 4:07



















          • Hmm... I think I kind of get it, but just for clarification, is there a reason why the return doesn't happen in the if statement "(set.name === name)"? My understanding was that if one of the recursions found a match, they would exit the loop and return the match using the "if/else". Is there a reason why this isn't the case? And also thank you for taking the time to review the code, I'll definitely look into it in detail for a better understanding.

            – Elbert Bae
            Nov 22 '18 at 3:46













          • So if you trace it though the tree above what happens is it calls findName() on the first offspring where the name doesn't exit. So that function doesn't return start because the condition doesn't match, and there's no children so it never runs the loop. The result is that it returns undefined. And returning from a for loop stops the loop and returns from the function before you get a chance to loop to the one containing what you want.

            – Mark Meyer
            Nov 22 '18 at 3:51











          • Oh! I see it now, wow. Thanks so much for the explanation Mark! Placement of the return, I'll keep an eye out for that moving forward.

            – Elbert Bae
            Nov 22 '18 at 4:07

















          Hmm... I think I kind of get it, but just for clarification, is there a reason why the return doesn't happen in the if statement "(set.name === name)"? My understanding was that if one of the recursions found a match, they would exit the loop and return the match using the "if/else". Is there a reason why this isn't the case? And also thank you for taking the time to review the code, I'll definitely look into it in detail for a better understanding.

          – Elbert Bae
          Nov 22 '18 at 3:46







          Hmm... I think I kind of get it, but just for clarification, is there a reason why the return doesn't happen in the if statement "(set.name === name)"? My understanding was that if one of the recursions found a match, they would exit the loop and return the match using the "if/else". Is there a reason why this isn't the case? And also thank you for taking the time to review the code, I'll definitely look into it in detail for a better understanding.

          – Elbert Bae
          Nov 22 '18 at 3:46















          So if you trace it though the tree above what happens is it calls findName() on the first offspring where the name doesn't exit. So that function doesn't return start because the condition doesn't match, and there's no children so it never runs the loop. The result is that it returns undefined. And returning from a for loop stops the loop and returns from the function before you get a chance to loop to the one containing what you want.

          – Mark Meyer
          Nov 22 '18 at 3:51





          So if you trace it though the tree above what happens is it calls findName() on the first offspring where the name doesn't exit. So that function doesn't return start because the condition doesn't match, and there's no children so it never runs the loop. The result is that it returns undefined. And returning from a for loop stops the loop and returns from the function before you get a chance to loop to the one containing what you want.

          – Mark Meyer
          Nov 22 '18 at 3:51













          Oh! I see it now, wow. Thanks so much for the explanation Mark! Placement of the return, I'll keep an eye out for that moving forward.

          – Elbert Bae
          Nov 22 '18 at 4:07





          Oh! I see it now, wow. Thanks so much for the explanation Mark! Placement of the return, I'll keep an eye out for that moving forward.

          – Elbert Bae
          Nov 22 '18 at 4:07













          0














          Do you think this will work? Move the recursion call out of the for loop. only if the match is not found in the for loop, you call the function findName. If possible, can you put your code in jsfiddle or somewhere so that I can take a look.



              findInTree(name) {
          let start = this.first(); //root object of the tree

          function findName (start, name) {
          if (start.name === name) {
          return start;
          } else {

          for (let set of start.offspring) {
          if (set.name === name) {
          console.log(set); // returns the correct set!
          console.log(set.name === name) //returns true;
          return set;
          }
          }
          return findName(set, name); //if the match is not found in the forloop, we call findname

          }
          }
          return findName(start, name);
          }





          share|improve this answer
























          • Just did a test run and unfortunately doesn't seem to work. Here's the jsfiddle link ! jsfiddle.net/4g6r5bz7

            – Elbert Bae
            Nov 22 '18 at 3:54













          • Most of your code looks good. I think you just need to add this to check whether match is undefined or not. let matchFound = findName(set, name); if(matchFound) return matchFound; I just saw that from the previous reply that you have already found the solution. Good to know.

            – Bala
            Nov 22 '18 at 4:23













          • Thank you for reviewing it! Yes, been looking into it to get a better understanding of how the matches take place in recursions, brushing up on how functions and loops react to returns!

            – Elbert Bae
            Nov 22 '18 at 4:34
















          0














          Do you think this will work? Move the recursion call out of the for loop. only if the match is not found in the for loop, you call the function findName. If possible, can you put your code in jsfiddle or somewhere so that I can take a look.



              findInTree(name) {
          let start = this.first(); //root object of the tree

          function findName (start, name) {
          if (start.name === name) {
          return start;
          } else {

          for (let set of start.offspring) {
          if (set.name === name) {
          console.log(set); // returns the correct set!
          console.log(set.name === name) //returns true;
          return set;
          }
          }
          return findName(set, name); //if the match is not found in the forloop, we call findname

          }
          }
          return findName(start, name);
          }





          share|improve this answer
























          • Just did a test run and unfortunately doesn't seem to work. Here's the jsfiddle link ! jsfiddle.net/4g6r5bz7

            – Elbert Bae
            Nov 22 '18 at 3:54













          • Most of your code looks good. I think you just need to add this to check whether match is undefined or not. let matchFound = findName(set, name); if(matchFound) return matchFound; I just saw that from the previous reply that you have already found the solution. Good to know.

            – Bala
            Nov 22 '18 at 4:23













          • Thank you for reviewing it! Yes, been looking into it to get a better understanding of how the matches take place in recursions, brushing up on how functions and loops react to returns!

            – Elbert Bae
            Nov 22 '18 at 4:34














          0












          0








          0







          Do you think this will work? Move the recursion call out of the for loop. only if the match is not found in the for loop, you call the function findName. If possible, can you put your code in jsfiddle or somewhere so that I can take a look.



              findInTree(name) {
          let start = this.first(); //root object of the tree

          function findName (start, name) {
          if (start.name === name) {
          return start;
          } else {

          for (let set of start.offspring) {
          if (set.name === name) {
          console.log(set); // returns the correct set!
          console.log(set.name === name) //returns true;
          return set;
          }
          }
          return findName(set, name); //if the match is not found in the forloop, we call findname

          }
          }
          return findName(start, name);
          }





          share|improve this answer













          Do you think this will work? Move the recursion call out of the for loop. only if the match is not found in the for loop, you call the function findName. If possible, can you put your code in jsfiddle or somewhere so that I can take a look.



              findInTree(name) {
          let start = this.first(); //root object of the tree

          function findName (start, name) {
          if (start.name === name) {
          return start;
          } else {

          for (let set of start.offspring) {
          if (set.name === name) {
          console.log(set); // returns the correct set!
          console.log(set.name === name) //returns true;
          return set;
          }
          }
          return findName(set, name); //if the match is not found in the forloop, we call findname

          }
          }
          return findName(start, name);
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 3:36









          BalaBala

          954719




          954719













          • Just did a test run and unfortunately doesn't seem to work. Here's the jsfiddle link ! jsfiddle.net/4g6r5bz7

            – Elbert Bae
            Nov 22 '18 at 3:54













          • Most of your code looks good. I think you just need to add this to check whether match is undefined or not. let matchFound = findName(set, name); if(matchFound) return matchFound; I just saw that from the previous reply that you have already found the solution. Good to know.

            – Bala
            Nov 22 '18 at 4:23













          • Thank you for reviewing it! Yes, been looking into it to get a better understanding of how the matches take place in recursions, brushing up on how functions and loops react to returns!

            – Elbert Bae
            Nov 22 '18 at 4:34



















          • Just did a test run and unfortunately doesn't seem to work. Here's the jsfiddle link ! jsfiddle.net/4g6r5bz7

            – Elbert Bae
            Nov 22 '18 at 3:54













          • Most of your code looks good. I think you just need to add this to check whether match is undefined or not. let matchFound = findName(set, name); if(matchFound) return matchFound; I just saw that from the previous reply that you have already found the solution. Good to know.

            – Bala
            Nov 22 '18 at 4:23













          • Thank you for reviewing it! Yes, been looking into it to get a better understanding of how the matches take place in recursions, brushing up on how functions and loops react to returns!

            – Elbert Bae
            Nov 22 '18 at 4:34

















          Just did a test run and unfortunately doesn't seem to work. Here's the jsfiddle link ! jsfiddle.net/4g6r5bz7

          – Elbert Bae
          Nov 22 '18 at 3:54







          Just did a test run and unfortunately doesn't seem to work. Here's the jsfiddle link ! jsfiddle.net/4g6r5bz7

          – Elbert Bae
          Nov 22 '18 at 3:54















          Most of your code looks good. I think you just need to add this to check whether match is undefined or not. let matchFound = findName(set, name); if(matchFound) return matchFound; I just saw that from the previous reply that you have already found the solution. Good to know.

          – Bala
          Nov 22 '18 at 4:23







          Most of your code looks good. I think you just need to add this to check whether match is undefined or not. let matchFound = findName(set, name); if(matchFound) return matchFound; I just saw that from the previous reply that you have already found the solution. Good to know.

          – Bala
          Nov 22 '18 at 4:23















          Thank you for reviewing it! Yes, been looking into it to get a better understanding of how the matches take place in recursions, brushing up on how functions and loops react to returns!

          – Elbert Bae
          Nov 22 '18 at 4:34





          Thank you for reviewing it! Yes, been looking into it to get a better understanding of how the matches take place in recursions, brushing up on how functions and loops react to returns!

          – Elbert Bae
          Nov 22 '18 at 4:34


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423323%2frecursion-javascript-does-not-exit-recursion-out-of-if-statement%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          鏡平學校

          ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

          Why https connections are so slow when debugging (stepping over) in Java?