КОМЕНТАРІ •

  • @DaveGrayTeachesCode
    @DaveGrayTeachesCode 3 роки тому +21

    I recently saw someone comment that "Recursion is the parallel parking of programming". 😂 It does seem difficult at first, but this tutorial breaks down the concept of recursion while providing some standard examples as well as some real world examples where recursion can be applied. If you are new to Javascript, start with my full 8 hour course: ua-cam.com/video/EfAl9bwzVZk/v-deo.html

  • @atouchofa.d.d.5852
    @atouchofa.d.d.5852 3 роки тому +31

    That was a great intro! At first I thought there was an editing problem but you taught me what it was pretty easily!

  • @marcuslorenzo9705
    @marcuslorenzo9705 2 роки тому +9

    Dave, great intro! Btw, just want you to know that you are my primary source of Front End learning, for the last 4 months at least. Appreciate your work brother.

  • @danielvega646
    @danielvega646 10 місяців тому +3

    Substantial benchmark: In some languages (like all the low levels), recursion is converted into a loop, so it improves performance. In JavaScript this does not happen, however, so recursion has this cost of calling a function where the context has to switch and all the object literal must be tested again (name, arguments, lexical scope, the body of the function, etc.). So in JavaScript may be preferable to run a loop over recursion if performance is your pursue.

  • @kerrykreiter445
    @kerrykreiter445 4 місяці тому

    Dave, you are the Mother Theresa of programming! It is obvious you truly care for those of us who desperately need programming knowledge. Thank you!!

  • @youmnaification
    @youmnaification Рік тому +2

    The best. Real world examples solidify the understanding.

  • @taoloveu
    @taoloveu 2 роки тому +2

    This has to be one of the best if not THE BEST video I have seen on recursion

  • @koraysoydan282
    @koraysoydan282 2 роки тому +4

    You are really valuable teacher/dev. Thank you so much for your time and effort

  • @JPNSynster
    @JPNSynster 3 роки тому +3

    Love your videos, I decided to look up basics of recursion first then watch and make my solution and it was exactly the same as yours. This video does help reinforce what I read though and the real world examples are so helpful. I used recursion for the pascal's triangle in one of your previous videos I viewed as well to calculate the factorials.

  • @rick3741
    @rick3741 Рік тому

    Recursion was covered in the Eloquent JS book with a somewhat complicated context, in my opinion, for why the recursive function was needed, which I felt muddled the focus of the lesson. When, why, and how to implement recursion was still very fuzzy afterwards. Can't emphasize enough how the incremental build up of your examples, from simple to complex, made recursion MUCH easier to wrap my head around. Feeling a lot more confident in my understanding now. The real-life/practical examples (very rare) was the cherry on top. This whole vid is chef's kiss; if I could like it a million times, I would. Subscribed and hit the bell. Thank you, Dave!!!

  • @676005ga
    @676005ga 2 роки тому +1

    I love your explanation and real world examples!

  • @misterl8129
    @misterl8129 Рік тому +1

    I like the last excercise, I tried myself and failed, so I try again, took me 25 mins to have the solution but this type of things help us improving into recursion that at least for me, is difficult
    function getArtistNames2(dataObj, res = []) {
    Object.values(dataObj).forEach(x => {
    return Array.isArray(x)
    ? res.push(...x)
    : getArtistNames2(x, res)
    })
    return res
    }

  • @jasongionfriddo8342
    @jasongionfriddo8342 2 роки тому +1

    Great vid with great examples. I thought you did a great job explaining. Thank you !!

  • @rajastylez
    @rajastylez 2 роки тому +2

    Funny intro haha. I looked away from the video and thought did my computer freeze 😂.

  • @nagaistark
    @nagaistark 2 роки тому +2

    Top quality content. Absolutely mind-blowing

  • @phonethetnaing4655
    @phonethetnaing4655 Рік тому

    Greatest intro.

  • @lauris5275
    @lauris5275 Рік тому

    Learning JS for quite some time. And still recursion is one of those that i always forget if i dont use it often. Not the very easy recursion but something like looping nested arrays.

  • @stafa5568
    @stafa5568 Рік тому +1

    Lol, you got me real good at the beginning of the video... had to pause and check my video timeline again 😂😂😁😁

  • @hafizsakib2734
    @hafizsakib2734 2 роки тому +1

    Nice man!

  • @doniaelfouly4142
    @doniaelfouly4142 Місяць тому

    thanks

  • @enzoarguello512
    @enzoarguello512 Рік тому +1

    I love the intro.

  • @aarondiaz2506
    @aarondiaz2506 10 місяців тому

    I was having a hard time with how the call stack manage the functions calls so i made this to see it more graphically, essentially every function call can't finish if his child hasn't finish execution (eg: returning a value), hope it helps someone, It is intended just to see how recursion works in a more graphical way and i guess is not the best code to solve a problem since it in only work for factorial of 3. Happy coding :)
    function factorial3() {
    function factorial2() {
    function factorial1() {
    return 1;
    }
    return 2 * factorial1();
    }

    return 3 * factorial2();
    }
    // Calling factorial(3)
    const result = factorial3();
    console.log(result); // Output: 6

  • @marcod.643
    @marcod.643 3 роки тому +5

    And again you published another great video,
    and again you published another great and interesting video,
    and again you published another great and interesting and inspiring video. 😏😉😁

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode 3 роки тому +1

      😂🤣 I see you got the message! Thank you my friend. 🙏💯

  • @frankdouglas8146
    @frankdouglas8146 Рік тому +3

    Would you be able to explain the fibPos function at 9:30? Is the pos variable changing? I'm having trouble wrapping my head around that. Any explanation would be super appreciated.
    Great videos, thanks!

    • @isaacdruin
      @isaacdruin Рік тому +2

      It took me a second, too!
      const fibPos = (pos) => {
      if (pos < 2) return pos; // this is just a catch, if the number is 1 or 0, we return that number because it's the number at that position
      return fibPos(pos - 1) + fibPos(pos - 2);
      }
      console.log(fibPos(8));
      We are essentially doing the work backwards. (Omitted the function to make it less messy)
      call1: (8 - 1) + (8 - 2)
      call2: (7 - 1) + (7 - 2) | (6 - 1) + (6 - 2)
      call3: (6 - 1) + (6 - 2) | (5 - 1) + (5 - 2) | (6 - 1) + (6 - 2) | (5 - 1) + (5 - 2)
      ... etc.
      These calls continue till we get to 0 and 1 (the beginning) and their values (0 or 1) are summed up through the chain of returns.

    • @laffiny
      @laffiny 7 місяців тому

      i have the same issue and the below explanation didnt help. i would love to see that tree of steps

  • @shineLouisShine
    @shineLouisShine Рік тому +1

    Thanks.
    It feels like a very important concept,
    Which really requires lots of practicing...
    I wish this lesson would have come with some tasks/exercises or with recommended sources to dive in with..

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode Рік тому +2

      You're welcome! Simple exercise: Create an array with ten elements. Now write a function that grabs the first element of the array AND if more elements exist after the one it grabs, the function calls itself to grab the next element. A function calling itself is recursion. The ten element array is a simple practice example, but more real world, an API can send a response with 100 results and tell you more are available.

    • @shineLouisShine
      @shineLouisShine Рік тому +1

      @@DaveGrayTeachesCode
      The thing is that -
      1. Yet, it doesn't feels like enough practicing.
      2. I only managed to write a function that logged the array's elements into the console.
      It didn't actually return an array element... which feels like a failure.
      ------------------------------------
      let elements = ["how", "many", "items", "should", "i", "put", "in", "my", "small", "array"];
      let count = 0;
      const countElements = (someArr) => {
      if (!someArr) return console.log("There is no array!")
      if (someArr.length == 0) return console.log("An empty array");
      if (someArr.length == count) return console.log("And this is the entire array");
      console.log(someArr[count]);
      count++;
      countElements(someArr);
      }
      countElements(elements);

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode Рік тому +1

      @@shineLouisShine keep making progress!

  • @World_information5568
    @World_information5568 3 роки тому +2

    Thank you so much for your precious time ♥️

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode 3 роки тому

      You're welcome! 🙏

    • @World_information5568
      @World_information5568 3 роки тому +1

      @@DaveGrayTeachesCode sir I have learnt HTML CSS and intermediate JavaScript but I am facing difficulty to make projects by using this knowledge. What should I do. please reply me and tell me best way to learn web development your reply will help me.i am self taught learner.

    • @World_information5568
      @World_information5568 3 роки тому +1

      @@DaveGrayTeachesCode and please guide me what kind of projects should I make to master JavaScript.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode 3 роки тому

      @@World_information5568 I think we are all still working to master Javascript. The best we can do is strive for progress and continuous learning. It takes lots of practice. You can look at my Vanilla Javascript Projects playlist: ua-cam.com/video/s_Ie_yh_4Co/v-deo.html and you can also make your own projects which is always challenging. I'll keep adding more projects to that playlist, too. 😀🚀

    • @World_information5568
      @World_information5568 3 роки тому +1

      @@DaveGrayTeachesCode thank you sir 😊♥️

  • @saitejagatadi9711
    @saitejagatadi9711 Рік тому +1

    The definition lines you paste (only while explaining) is something even I also actually do it. 😁
    I would rate this as one of the way to explain beautifully bcoz people can only focus on those two lines to get the complete gist of what we're explaining

  • @Johnny-rn8fb
    @Johnny-rn8fb Рік тому +1

    👌

  • @muhammadfathurraiyan
    @muhammadfathurraiyan 4 місяці тому

    Terimakasih pak Dave, penjelasanya sangat jelas, walaupun masih kurang mengerti tapi saya tetap mendapatkan sedikit progress. Dapat saya simpulkan bahwasanya setiap recursive function membutuhkan if statement untuk melakukan perulangan apakah betul? dan terimakasih sekali lagi pak Dave, menonton video ini, saya bisa belajar 2 bahasa sekaligus, JavaScript dan English 😁😁

  • @rangabharath4253
    @rangabharath4253 3 роки тому +1

    awesome

  • @takisnani5337
    @takisnani5337 2 роки тому +1

    Great Content!
    Should I learn Algorithmes first to start with your Advanced JS Tutos?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode 2 роки тому +2

      That is not necessary. These advanced tutorials should help you solve algorithms afterwards though.

  • @user-mc2el1fi8w
    @user-mc2el1fi8w 9 місяців тому

    Isnt there a risk for a Stack overflow if Recursion is used?

  • @Ath9493
    @Ath9493 3 місяці тому

    Starting of the video got me 😂

  • @mahioocode
    @mahioocode Рік тому

    wait a minute if u start counting the Position from 0 isn't 8th position from the sequence is 13 ?? 21 is 9th Position. Mr. @DaveGrayTeachesCode

  • @avertry9529
    @avertry9529 Рік тому +1

    Thanks I thought this was my answer, but add:
    { another: 'obj value will crash this'},
    RangeError: Maximum call stack size exceeded
    Why do all the values need to be arrays and not Objects?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode Рік тому +1

      I created this over a year ago and do not remember the examples without viewing it myself. That said, they are just examples. You can use recursion with arrays or objects. Recursion is a concept and not a specific function.

  • @GoldenEmperor5Manifest
    @GoldenEmperor5Manifest 11 місяців тому

    I struggle so hard with math logic when it comes to programming. I am, for the life of me, trying to understand your fibonacci sequence code but I can't figure it out.
    It's deleting two from the array, okay, but which two specifically is that slicing? Is it slicing the two in the sequence before the next sequence?
    I don't understand why num = -1 at the end?
    and how does num become less than 2 when it's iterating into oblivion? I'm sooo confused about that.
    I get the concept of recursion, but I don't get the programming logic of your simple example and I need to overcome this. Anybody out there have suggestions on how to improve my logic on things like this so these sort of examples aren't so mind bending?
    I wish I could visualize this somehow. How did someone think of this? I've noticed that in some ways, I'm a fairly smart dude but the second we get to trying to make math logic into programming I'm completely mentally deficient. I have to get good at whatever this subject of reasoning is called. Have to. Else, I'm screwed in life because I'm not cut out to be blue collar. Besides I'd never forgive myself for not overcoming this hurdle. I really think when it comes to ACTUAL coding, not styling or tag related code because that's crazy easy for me, but actual coding for me is like being a fish that is trying to climb a tree. I have got to evolve something to grab these branches with.

  • @azumatomlinson3474
    @azumatomlinson3474 2 роки тому +1

    Book mark for later:
    7:33

  • @emreozgun3846
    @emreozgun3846 3 роки тому +1

    17:35, line 146, why do we need that return ?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode 3 роки тому +4

      Thanks for asking, and good question. Ah, I see you said line 146. I looked at the return on line 152 first. The return on line 146 handles any nested arrays and allows them to be passed to the recursive call. While a little difficult to describe, it may be easier to understand if you remove the return and see what happens without it. 😀

  • @aardvarkarmy
    @aardvarkarmy Рік тому

    Isn't fibonacci position 1 equal to the value of 0? The fibonacciPos function would return 1 for position 1.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode Рік тому

      Man, I need more coffee this morning OR I should wait to reply until later in the day 😆 Third attempt... You have to think about the positions of an array and they start with zero. This function works as expected because the zero position is 0. The 1 position is 1. The 2 position is 1, and on up the fib sequence. I do understand the confusion as I attempted to answer this with inadequate coffee and over a year and a half after I made the video lol.

  • @alatamal
    @alatamal 2 роки тому +1

    Hahahaha good and simple joke at the beginning, those are the best.

  • @dumchik7290
    @dumchik7290 2 роки тому +1

    //Recursive anonymous function
    //Let's say I have a basic recursive function:
    function recur(data){
    data = data + 1;
    var nothing = function(){
    recur(data);
    }
    nothing();
    }
    //How could I do this If I have an anonymous function such as...
    (function (data){
    data = data + 1;
    var nothing = function(){
    //Something here that calls the function?
    }
    nothing();
    })();

  • @T25de
    @T25de Рік тому

    🤙🤙🤙🤙

  • @yubrajkhatri777
    @yubrajkhatri777 28 днів тому

    At first i thought that i mismatch something in the yt setitngs

  • @shineLouisShine
    @shineLouisShine Рік тому +1

    All of your Advanced Javascript Principles playlist is -
    You - sharing your knowledge, much more than it is -
    You - teaching.
    And for me, who came to your channel with a huge desire to learn,
    It is a huge disappointment which requires me to keep looking for teachers who also give their viewers exercises to truly practice.
    I am thankful to you for showing your knowledge,
    But I'm heartbroken for not being able to actually execute most of it.
    You use to response: "keep making progress!",
    But unfortunatly I can barely see myself progress here on Advanced Javascript.
    I will probably give another try to your approach (after learning Advanced Javascript elsewhere),
    By watching your Node.js playlist.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode Рік тому +3

      I know my teaching style is not for everyone. I hope you find something that works for you. It is unfortunate that you would tell anyone providing a free resource that their efforts are "a huge disappointment". Please be kind, and I wish you the best.

    • @shineLouisShine
      @shineLouisShine Рік тому +1

      @@DaveGrayTeachesCode
      You know very well that I do appreciate your efforts, and you know very well that I've shown it few times already.
      Taking my last message as if I'm not grateful for everything you did is entirely misinterpretion of my words.
      In addition, if it wasn't clear enough:
      A big part of my disappointment came directly from the expectations which I developed in my mind during your HTML/CSS courses for beginners.
      I admit: I had very high hopes about this advanced JavaScript course.
      For me, advanced principles are currently the most important bricks in this wall of knowledge that I try to build...
      But instead of building a wall of knowledge, I feel that I've left with no materials to truly put those bricks one next to and on each other... which is unfortunate.
      After the beginners courses I had this belief that you will be the one who will lead me safely towards the "next level"...
      But with the absence of actual exercises and practice - I ended up without the tools that I was so enthusiastic about while reading the titles.
      Sure, the videos represent how professional are you, and I'm happy for you, and I'm happy for anyone who find them helpful, but for me - the way you chose to guide the way from beginner level to advance level is mostly frustrating.

  • @THEARPE07
    @THEARPE07 2 роки тому +2

    this is no for beginners for sure

  • @earnyourfinancialfreedom
    @earnyourfinancialfreedom 2 роки тому +1

    Not beginner friendly. This tutorial can only be understood by people who are already grounded in coding

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode 2 роки тому +3

      Agreed. It is in my Advanced JS playlist and is not titled "for beginners". Recursion is an advanced concept overall.

  • @_ademmeral
    @_ademmeral Рік тому

    Google does that intentionally 🤣🤣🤣

  • @STUPIDYOUTUBE_AI
    @STUPIDYOUTUBE_AI 2 роки тому +1

    While this tutorial is okay at best, It would have been nice if you have considered simulating the code and showing the output on each call to recursion. Instead, you showed us the code and ran it and produced the desired result, so what do newbies get here, copy-paste ideas?