Thinking Recursively | Microsoft Interview Question | Software Engineer UI/Frontend

Поділитися
Вставка
  • Опубліковано 17 тра 2019
  • Thinking Recursively is very important if you're a Software Engineer. Be it Microsoft Interview, or even while in day to day job, Recursion plays a very important role in Software Engineer's life. In this video, I'll solve a Microsoft Interview Question, just like how candidates do in the interview. Will also tell you how to create a mental model of solution and think while approaching such questions.
    It's not necessary that you solve the question in the first attempt. Most of the time we have to think step by step and gradually come up to the final solution.
    Link to code - codepen.io/akshaymarch7/pen/x...
    Also, help me with the following for the next videos:
    1. Continue using whiteboard just like interviews to solve problems
    2. Use a code editor and type code while explaining
    If this video was helpful, give it a thumbs up and subscribe to my channel for more such videos. 🔔
    Link to Subscribe: ua-cam.com/users/akshaymarch...
    If you want me to cover any specific topic, then comment down below. I would be happy to help you.
    If you find my videos helpful,
    then please support this channel by buying a coffee,
    www.buymeacoffee.com/akshayma...
    Cheers,
    Akshay Saini
    akshaysaini.in
    Would love to Stay Connected with you ❤️
    LinkedIn - / akshaymarch7
    Instagram - / akshaymarch7
    Twitter - / akshaymarch7
    Facebook - / akshaymarch7
    #Javascript #JavascriptInterviewQuestions #AkshaySaini

КОМЕНТАРІ • 143

  • @akshaymarch7
    @akshaymarch7  5 років тому +14

    Watch my full Microsoft Interview Experience here - ua-cam.com/video/pjs1ZLjZhzk/v-deo.html
    I've discussed all the 4 rounds I faced in detail along with the questions asked in each round.

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

      Akshay, did you get the output. Because I'm getting range error call stack size exceeded

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

      @@kirthijain9891 Base condition check kar aache se!

  • @TanmayKamath
    @TanmayKamath 4 роки тому +31

    I had a situation where i had to return a simple object by filtering through a nested object and build a treeview. Thinking recursively solved my problem :-).
    Great explanation Akshay )!

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

    when you explain, every step unfolds so clearly. If I try the same, hell breaks loose!

  • @VijayKumar-zx5bm
    @VijayKumar-zx5bm 5 років тому +3

    Very informative and good explanation with suitable example . This is a common scenario in most of the front-end applications . Flattening the object improves the efficiency while searching by avoiding looping through the object multiple times . Will definitely try to apply this next time .

  • @mangeshgupta5677
    @mangeshgupta5677 4 роки тому +1

    I had learned this recursion in my University syllabus, but they haven't explained how much it can bhi usefull in real application problems.
    Thank You Very Much 😊

  • @suryapratap9915
    @suryapratap9915 5 років тому +7

    Thank you so much Akshay for making this video. I was able to recall this immediately when today I was solving an interview problem related to this but slightly modified. and finally i solved it. Thanks a lot. :D

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

    Your video is increasing the thinking level when I see any JS problem. Thank you 😊

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

    Thank you for specifically walking through how user would interact with the function. That was super helpful in solidifying my understanding of the code.

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

    while watching your videos, I recall the days in Oracle while solving a similar kind of recursive problem to generate a tree structure in UI. Enjoyed every bits & pieces of the video. Great Video, KEEP IT UP.

  • @abhijeetyadav1647
    @abhijeetyadav1647 5 років тому +7

    Recursion! This was a much needed video. Thanks Akshay.

  • @kanz831021
    @kanz831021 4 роки тому +1

    Thank you so much for a crisp explanation! It helps a lot and gave me a idea of 'How to think Recursively' !

  • @sandeepsahoo4573
    @sandeepsahoo4573 Рік тому +7

    I learn a lot from your videos. Thanks for making such contents.

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

      Thank you so much for supporting my channel, Sandeep. This means a lot. ❤️

  • @Gauravguptakumar
    @Gauravguptakumar 4 роки тому +1

    Super awesome.
    Recursion concept is haunting me from start of my career.
    You made it very easy.

  • @abhisheksengupta4159
    @abhisheksengupta4159 4 роки тому +1

    Great video, really allowed me to understand when to use recursions. I am from Java background but the code is very well explained... Keep up the good work

  • @rumelabasuroy6586
    @rumelabasuroy6586 2 роки тому

    Thanks Akshay ! I can't explain how much this video helped me in my works. Thank you for sharing this video. Its a great explanation!

  • @akhila.sakhila9018
    @akhila.sakhila9018 4 роки тому

    Thank you Akshay , I juet implemented in real time erp soln , this helped awesome and also thanks for sharing your uber use case as well :) Please keep sharing your experiences ♥️

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

    You are amazing tutor Akshay, your video series is simply superb...!!! TYSM

  • @MohitKumar-nh1qb
    @MohitKumar-nh1qb 2 роки тому +2

    Hello Akshay,
    Thanks for the solution. I faced this question while interviewing at Bloomberg. I did it in a very long way.
    The interviewer asked me to refactor my code and give a solution, but as you mentioned we should dry run our code, and then we should implement.
    My Solution:
    function isNonPrimitive(obj) {
    return ['[object Object]', '[object Array]'].includes(
    Object.prototype.toString.call(obj)
    )
    }
    function iterateObj(obj, str) {
    if (!isNonPrimitive(obj)) console.log(str + ' -> ' + obj)
    else if (Array.isArray(obj)) {
    obj.forEach((val, index) => {
    if (Object.prototype.toString.call(val) === '[object Object]') {
    for (let arr of Object.entries(val)) {
    if (!isNonPrimitive(arr[1])) {
    console.log(`${str}[${index}].${arr[0]} -> ${arr[1]}`)
    } else {
    if (str) {
    str = `${str}[${index}].${arr[0]}`
    } else {
    str = arr[0]
    }
    iterateObj(arr[1], str)
    let lastIndex = str.lastIndexOf('.' + arr[0])
    str = str.substring(0, lastIndex)
    }
    }
    } else {
    console.log(`${str}[${index}] -> ${val}`)
    }
    })
    } else {
    for (let arr of Object.entries(obj)) {
    if (str) {
    str = str + '.' + arr[0]
    } else {
    str = arr[0]
    }
    iterateObj(arr[1], str)
    let lastIndex = str.lastIndexOf('.' + arr[0])
    str = str.substring(0, lastIndex)
    }
    }
    }

  • @testingtesting4984
    @testingtesting4984 5 місяців тому

    Great task to practice recursion. Thanks for your work!

  • @syedmuhammadzaeemhasankazm7740
    @syedmuhammadzaeemhasankazm7740 4 роки тому +1

    Thanks for great explanation. I learned something new and extremely amazing today. :)

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

    It is a nice video to the explanation of Recursion and way to solve a problem using recursion. Thanks Akshay

  • @JavaScriptWithSohail
    @JavaScriptWithSohail 4 роки тому +18

    Can you do the opposite? Take output of this program and retrieve back the question!
    Answer: jsbin.com/hudufif/edit?js,console

  • @karnot301
    @karnot301 4 роки тому +1

    Hi your videos are great , authentic and it encourages everyone that you can become good at it 😊
    I have a problem of getting deep into the code and then get confused by the complexity of the functions like when you want to see how react , redux , jQuery works under the hood .
    Most confusion comes when I can't get the flow mostly with the function passing here and there .
    Can you share your experience with this ?
    Thanks for every video u have made ! I have almost watched all of them 🙏🙏

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

    Thanks for this video and please make more such videos related to solving programming questions

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

    You are the most awesome guy I ever seen. Thank you so much !

  • @theakshaymohan
    @theakshaymohan 2 роки тому

    Akshay bhaii! Itni mehnat! kyun 😢 ?? Thanks a lot for such a beautiful explantation! I was always kinda scared of recursion because I didn't know how it exactly worked or how to solve a problem on recursion! but this video gave me a boost in confidence that I can also solve problems on recursion! Always grateful to you ❤️

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

    Hi sir Akshy Saini, Thank you so much keep it up. God bless you. ❤️

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

    Vinoth love >> Akshay:
    30:23 better example taxanomy like you said electronic under refegerator, mobile, motor, fans,
    then refegerator under recurservelly, samsung, LG, BoSS, and some other list .
    super bro i clear... love you

  • @amitnain8489
    @amitnain8489 4 роки тому

    you are really great , best video of entire youtube

  • @imranshaikh115
    @imranshaikh115 5 років тому +4

    Marvellous explanation for Recursive approach. God may filled the joy in your life

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

      God won't after listening to your english

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

      @@pleasesirmorevideos4684
      God will surely listen. Language is not a barrier if blessings come from the heart. And Akshay has blessings of all as he is trying to help with all his efforts 🙏. Great explanations 👍 And just for info, this channel is purely for people with positive thinking.

  • @vishalsanserwal603
    @vishalsanserwal603 5 років тому +1

    Nice! Keep up the good work😊✌️

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

    Very good explanation for Recrusion.👍

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

    Great explanation Akshay! Really clear

  • @AmarSingh-uw1db
    @AmarSingh-uw1db 5 років тому

    Thank you so much for explaining this problem

  • @Raju-un8ir
    @Raju-un8ir 5 років тому +1

    Nice one..also do one video for performance tuning in JavaScript..thnx

  • @knowledgefacts4602
    @knowledgefacts4602 2 роки тому

    Thank you Akshay , Great video an recursion
    Helped me

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

    Great explanation ,akshay! 🔥

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

    Hi Akshay, Thanks again for your great tutorial!! Could you make a video on ReactJs or NodeJs if possible.

  • @nostacktofullstack
    @nostacktofullstack 4 роки тому

    Great video, Please also come up with some DS and Algo videos.

  • @deeproy7292
    @deeproy7292 4 роки тому +1

    I thought of using stacks for saving the intermediate object states

  • @VikasKumar-zw7ko
    @VikasKumar-zw7ko 3 роки тому

    Thanks, this will solve a lot many problems. This will come handy when we will break the data that we are getting from API

  • @AdnanAli-cp9hk
    @AdnanAli-cp9hk Місяць тому

    thankyou so much from the bottom of my heart for such a wonderful explanation, Sir.!

  • @bhatvikrant
    @bhatvikrant 4 роки тому

    Thanks akshay! it was a great video!

  • @sourav_singh_diaries
    @sourav_singh_diaries 4 роки тому +1

    Great video Akshay. By the way I think using "for..in loop" is not good here because it traverses even the prototypes of object which we don't want here.

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

    Thanks sir I am looking for this best vedio on UA-cam

  • @deeprajdey1364
    @deeprajdey1364 4 роки тому +1

    Superb Sir awesome video....😊

  • @vivekcool54
    @vivekcool54 5 років тому +2

    Good to see u on utube bro..😉 all d best ..👍 #akshay #vivekgoyal

    • @akshaymarch7
      @akshaymarch7  5 років тому

      Hi Vivek, Thanks a lot. It's great to see your text here. Ping me on WhatsApp, I lost your number. 😊👍

  • @momentswithmanisha
    @momentswithmanisha 4 роки тому +1

    You are superb sir🙏

  • @rahulpurohit2461
    @rahulpurohit2461 4 роки тому +1

    You are so awesome man.

  • @soni.himansh
    @soni.himansh Рік тому

    Beautiful Explaination.

  • @deepak_life_in
    @deepak_life_in 3 роки тому +6

    typeof(object) and typeof(array) would be "object" it self. How would we solve that edge case ?

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

      Array.isArray(arr) would return true for an array.

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

      I used this --> if (typeof obj[key] === 'object' && !(obj[key] instanceof Array))

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

      @@PushpakB541Array.isArray()

  • @naruto5437
    @naruto5437 4 роки тому +1

    great explanation....

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

    A suggestion from my side would be while doing dry run, create recursive tree and write recursive calls alongside it. It will help alot in visualisation

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

    Hi Akshay!! It was a great video! Also.. are you from Dehradun? 😆

  • @sushilkumartechy
    @sushilkumartechy 4 роки тому

    great explanation !!

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

    Nice question!
    Thanks!

  • @anuraggupta4555
    @anuraggupta4555 2 роки тому

    Thank you for sharing!!

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

    thanks a lot for this knowledge.. It is very helpful !!

  • @rahulsonone6673
    @rahulsonone6673 4 роки тому

    nice explanation Akshay... why don't you write the code on EDITOR after the explanation instead of board. This will solve the space problem.

  • @kashishjain78
    @kashishjain78 4 роки тому +1

    enjoyed a lot

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

    awesome ❤️

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

    Hello Akshay Sir, would you please discuss on GENERATOR Function and Async Await in details? Please?!

  • @viraj268
    @viraj268 5 років тому +2

    You will need to handle cases when object is null and an array. As typeof will return object for null and Array as well. For null it should go to else part and for an array i think you will have to append the index of object in array, depends on what your interviewer wants.

    • @akshaymarch7
      @akshaymarch7  5 років тому

      Exactly, that's what I mentioned in the video also. We can improve this more to handle these corners cases. That's when you should always ask questions to your interviewer and clarify such cases.

    • @aviquid
      @aviquid 5 років тому

      Yes, the null case has to be handled. However, the array case is handled here properly, where the index of the array will get appended to the key. There is no need of extra code in case of array.

    • @viraj268
      @viraj268 5 років тому

      @@aviquid how the array would behave depends on the interviewers perception.

    • @viraj268
      @viraj268 5 років тому

      Like here interviewer might not want to iterate over the array. Also he might say that iterate only over the objects own property and not its prototypes.

  • @kanishkkunal6622
    @kanishkkunal6622 2 роки тому

    Thnx akhsay bhai

  • @hussainratlamwala3628
    @hussainratlamwala3628 5 років тому +1

    nice bro

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

    Hi Akshay, First of all, thanks a lot for such informative videos that simplify the concepts, they really helped me in my job hunting.
    I had a request, actually, I was trying to access the nested objects in one of a machine test in a company, but I got stuck at a point, I was able to traverse through the object, but I had a situation wherein I need to print some value from the object, on the basis of some search criteria, like i had a nested object wherein suppose I got a match with some property, then I needed to go back to its parent to parent object and access some of its property and print it, I got stuck there, Can you please help me with this, how can I keep reference of previously accessed object, in a nested object. I am not sure, if you got my question.

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

    What if there is an array value , because typeOf(array) is also a object right

  • @ajayrawat2168
    @ajayrawat2168 2 роки тому

    Cute, how he explains and check everything is fine or not😅😀

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

    Hi akshay
    I have a stupidest doubt in recursion that how return works i.e when we do return how execution stack works. Can you prepare video on this.

  • @deeproy7292
    @deeproy7292 4 роки тому

    thank you

  • @XploreXperience
    @XploreXperience 3 роки тому +5

    Hi Akshay, a question asked in Microsoft interview was around closure and everyone knows it by now, but a follow up question is around garbage collection of the closed variable. Could you have a session around it ?

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

      JavaScript will trigger garbage collection once the variable goes out of scope. for reference type you can manually garbage collect by simple assign them as null this will garbage collect them but I suggest you better leave this to JavaScript engine it will take care of it.

  • @ManvendraMaan
    @ManvendraMaan 5 років тому +2

    Thank you for that solution as it was really good to understand. But I have one question, if you have to avoid to declare that result object in global scope so that we won't pollute our global scope then what would you do? Just an improvisation with JavaScript in your solution.

    • @akshaymarch7
      @akshaymarch7  5 років тому +4

      Pass it down as the third parameter to the magic function. I missed that part, but yeah check the link to code in description, I've done that there.

    • @ManvendraMaan
      @ManvendraMaan 5 років тому

      Actually my point was regarding not to declare the result object outside of magic function. Think about a solution where you can declare it within the magic function so that it cannot be modified from outside the function. Hint : Using closure in JavaScript

    • @ManvendraMaan
      @ManvendraMaan 5 років тому

      @Nitish Narang Thank you for your iterative approach which is nice. Eventually I solved it recursively also with concept of closure in JS. Thanks again to Akshay Saini for giving simple approach to the problem.
      //Solution
      let user ={
      name: "Akshay Saini",
      address: {
      personal: {
      city: "Dehradun",
      state: "Uttrakhand",
      area: "Majra",
      },
      office: {
      city: "Hyderabad",
      area: {
      landmark: "Hi Tech",
      }
      }
      }
      }
      let magic = () => {
      let finalObj= {}; // result object
      return function magicalFn(obj, parent)
      {
      for(let key in obj){
      if(typeof obj[key] === "object"){
      magicalFn(obj[key], parent + "_" + key);
      }
      else {
      finalObj[parent + "_" + key] = obj[key];
      }
      }

      return finalObj;
      }
      }
      let getCombinedKeys = magic();
      console.log(getCombinedKeys(user, "user"));

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

      @@ManvendraMaan I'm getting Range error Call stack size exceeded

    • @johndoe-cq3de
      @johndoe-cq3de 3 роки тому +1

      @@kirthijain9891
      let finalObj = {};
      const modifyObj = (obj, parentName = "user") => {
      for (let key in obj) {
      if (typeof obj[key] === "object") {
      modifyObj(obj[key], parentName + "_" + key);
      } else {
      finalObj[parentName + "_" + key] = obj[key];
      }
      }
      return finalObj;
      };
      console.log(modifyObj(user));
      Solution 2(if you don't want to use finalobj as global) :
      const modifyObj = () => {
      let finalObj = {};
      return (recursive = (obj, parentName = "user") => {
      for (let key in obj) {
      if (typeof obj[key] === "object") {
      recursive(obj[key], parentName + "_" + key);
      } else {
      finalObj[parentName + "_" + key] = obj[key];
      }
      }
      return finalObj;
      });
      };
      console.log(modifyObj()(user));

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

    What id I don't want to use global variable finalObj. I just want my function to return final destructed obj?

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

    We can also use for of loop ?

  • @akhilraghav3064
    @akhilraghav3064 4 роки тому

    hI bro can you explain about event looping in javascript?

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

    the Vedios are very good......Sir is there any pdf or word format document to entire vedios.(like to remember explanation)...?

  • @mathanprakash5685
    @mathanprakash5685 2 роки тому

    Hi bro, I would like to request if you are free plz make the React js all concepts tutorial for your Juniors. Thanks

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

    I was able to solve it :D
    the only difference is I used the spread operator in order to track the parent's key.
    const magic = (obj, ...keyNames) {}

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

    30:00 How does final object second property know that it's grandparent was user and how does it know that it should put an underscore before?

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

      @WMTIT As per your question, grandparent will be "user" because we are passing it in actual argument when function call and we are appending it in recursive call .
      It doesn't know about underscore we are appending it in recursive call and we are doing it because the output demands in that way ,It("underscore") could be optional and depends on interviewer ask.

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

    Bro tell me in case of array of objects

  • @aarcheeecya
    @aarcheeecya 5 років тому +4

    The way you teach from ground up, is really awesome. You should use UA-cam promotion to lift your channel up, i am accessing this video from US, and every time i have to type your name to see your content, it just never show up in relevant videos at side. Amazing work !!!!

    • @akshaymarch7
      @akshaymarch7  5 років тому +3

      Thank you so much for your kind words. I'm just trying to reach audience by organic reach and don't feel like spending money on marketing or ads. Will do that once I start generating revenue from here itself. I've some plans.
      But yes, if you like the videos then do share it with your network. It really motivates me to come up with more such content. Thanks a lot.

    • @aarcheeecya
      @aarcheeecya 5 років тому

      @@akshaymarch7 That is really nice and great intention. Best wishes and i am a subscriber already. And yeah do catch some sleep.

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

    Got a max call size exceed if i used Object.entries. Didn't get why.

  • @mayankraghuvanshi486
    @mayankraghuvanshi486 5 років тому

    Sir,
    I am a big fan of yours. I am trying to learn base web library implemented by uber but. sir I am really stuck. I can't even perform normal thing using this like form validation. sir can you help me just if you can give me some guidance, please.

    • @akshaymarch7
      @akshaymarch7  5 років тому +1

      Hey Mayank, keep trying. It might be a little complex in the beginning but that's how you learn right?
      Keep trying, you'll be better. Read blogs or follow some tutorials, that would help you. Don't give up, all the best !

  • @tajstudentilhomjon757
    @tajstudentilhomjon757 6 місяців тому

    I do not understand how the functions goes to office object after personal obj , could anyone explain what happens over there ?

  • @manu8893
    @manu8893 2 роки тому

    Hey Akshay I am thinking about those who dislike this video. They will punish by garun puran law.
    #CheersAkshay

  • @ranjandass13
    @ranjandass13 2 роки тому

    Nice video but I had to watch it in 1.5x, :)

  • @Nikhilkumar-yh7yc
    @Nikhilkumar-yh7yc 3 роки тому

    Can we have a deep knowledge of JavaScript to learn Reactjs .

    • @Nikhilkumar-yh7yc
      @Nikhilkumar-yh7yc 2 роки тому

      NO one replied on it.. now i having a deep knowledge in JS , and I am Good in react . No you don't need a deep knowledge to learn react. required Es6 features , concept of this.
      but guys first focus on JS . it will make u fall in love with it.. You will feel more comfortable in React .

  • @themynamesb
    @themynamesb 4 роки тому

    Hi Akshay,
    I tried it. My logic went fine. But the issue is in my returned value.. Can you please tell why the value returned to me is a blank object {} instead of filled object..
    Code link: jsbin.com/sopaqoquyo/1/edit?html,js,console,output

  • @ankitbaid11326
    @ankitbaid11326 5 років тому

    your approach is good, Instead of storing data in Global you should handle it inside functional.
    JUST A SOLUTION. I REALLY LIKE YOUR APPROACH TOO.
    function getFinalObject(obj, parent) {
    const newObject = {};
    for (key in obj) {
    if (typeof obj[key] == 'object') {
    let nestedObj = getFinalObject(obj[key], key);
    for (nestedKey in nestedObj) {
    newObject[`${parent}_${nestedKey}`] = nestedObj[nestedKey];
    }
    } else {
    newObject[`${parent}_${key}`] = obj[key];
    }
    }
    return newObject;
    }

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

    Can anyone explain how
    1+[4] returns 14 I don't get this

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

    05:26 I thought you have two thumbs like Hrithik

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

    If(typeof(obj[key]) ! =object && ! Array. IsArray(obj[key]) this would be more guarded case

  • @shubhamgaur3629
    @shubhamgaur3629 2 роки тому

    As the result the outcome is not as we think sir during execution of the program sir could you do this on your vs- code Sir

  • @Zaheer__zk40
    @Zaheer__zk40 2 місяці тому

    A small change in
    Solution:
    const magicFn = (inputObj, parentName) => {
    let finalObj = {}
    for(let key in inputObj) {
    if(typeof inputObj[key] === 'object') {
    let nestedObj = magicFn(inputObj[key], parentName + '_' + key);
    finalObj = { ...finalObj, ...nestedObj };
    } else {
    finalObj[parentName + '_' + key] = inputObj[key];
    }
    }
    return finalObj;
    }
    const user = {
    name: 'Jon doe',
    address : {
    personal : {
    city: 'Any',
    pincode: '999999'
    }
    },
    profession: 'Software Developer'
    }
    console.log(magicFn(user, "user"))

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

    I'm getting range error Maximum Call stack size exceeded

  • @nithinsastrytellapuri291
    @nithinsastrytellapuri291 4 роки тому

    Hello Akshay,
    i tried to solve this problem on my own and I ended up using similar logic. Here's my solution link :
    codesandbox.io/s/recursion-x0i67?file=/src/index.js
    While I made the solution generic enough I have a few questions:
    As you can see from the result, I am printing only "key names" for top-level keys rather than "user_name" i am printing only "name". So how do I solve this? I don't want to hardcode the first object name as you did in the video. I want to make it generic but I couldn't understand how we can get the object name in JS. let's say I am traversing "obj" object, how do I print the name of it? Please reply if you know how to handle such a scenario.
    I also feel that there are too many if checks in the logic that I have written, any suggestions that can have? please comment. Thank you

    • @yadneshkhode3091
      @yadneshkhode3091 2 роки тому

      i had same problem so i thought wrapping input in another object and use for in to get key name

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

    29:50 how it will go there

  • @abhinavghosh725
    @abhinavghosh725 4 роки тому

    good explanation!
    just a suggestion: you should have taken a tree question instead to explain recursion!

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

    Solved it in 15 minutes only. : D

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

    Here for the thumbnail