Watch my full Microsoft Interview Experience here - ruclips.net/video/pjs1ZLjZhzk/видео.html I've discussed all the 4 rounds I faced in detail along with the questions asked in each round.
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 )!
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 😊
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
Thank you for specifically walking through how user would interact with the function. That was super helpful in solidifying my understanding of the code.
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 .
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.
@@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.
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) } } }
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
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
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 ❤️
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 ♥️
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.
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.
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.
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.
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 🙏🙏
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.
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
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.
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
@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"));
The way you teach from ground up, is really awesome. You should use RUclips 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 !!!!
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.
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.
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 ?
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.
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; }
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.
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 !
@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.
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 .
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
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
Watch my full Microsoft Interview Experience here - ruclips.net/video/pjs1ZLjZhzk/видео.html
I've discussed all the 4 rounds I faced in detail along with the questions asked in each round.
Akshay, did you get the output. Because I'm getting range error call stack size exceeded
@@kirthijain9891 Base condition check kar aache se!
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 )!
I learn a lot from your videos. Thanks for making such contents.
Thank you so much for supporting my channel, Sandeep. This means a lot. ❤️
when you explain, every step unfolds so clearly. If I try the same, hell breaks loose!
Recursion! This was a much needed video. Thanks Akshay.
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 😊
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
Your video is increasing the thinking level when I see any JS problem. Thank you 😊
Thank you for specifically walking through how user would interact with the function. That was super helpful in solidifying my understanding of the code.
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 .
Great task to practice recursion. Thanks for your work!
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.
thankyou so much from the bottom of my heart for such a wonderful explanation, Sir.!
Super awesome.
Recursion concept is haunting me from start of my career.
You made it very easy.
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!
Marvellous explanation for Recursive approach. God may filled the joy in your life
God won't after listening to your english
@@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.
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)
}
}
}
Thank you so much for a crisp explanation! It helps a lot and gave me a idea of 'How to think Recursively' !
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
Thanks sir I am looking for this best vedio on RUclips
Hi sir Akshy Saini, Thank you so much keep it up. God bless you. ❤️
Thanks, this will solve a lot many problems. This will come handy when we will break the data that we are getting from API
exactly
You are amazing tutor Akshay, your video series is simply superb...!!! TYSM
You are the most awesome guy I ever seen. Thank you so much !
you are really great , best video of entire youtube
Great explanation ,akshay! 🔥
Great explanation Akshay! Really clear
It is a nice video to the explanation of Recursion and way to solve a problem using recursion. Thanks Akshay
Can you do the opposite? Take output of this program and retrieve back the question!
Answer: jsbin.com/hudufif/edit?js,console
Nice! 😇
I'm getting range error call stack size exceeded
Beautiful Explaination.
Very good explanation for Recrusion.👍
Superb Sir awesome video....😊
Nice question!
Thanks!
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
Thank you Akshay , Great video an recursion
Helped me
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 ❤️
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 ♥️
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.
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.
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.
@@aviquid how the array would behave depends on the interviewers perception.
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.
You are superb sir🙏
Hi Akshay!! It was a great video! Also.. are you from Dehradun? 😆
Thank you for sharing!!
Thanks akshay! it was a great video!
Thanks
You are so awesome man.
Thanks for great explanation. I learned something new and extremely amazing today. :)
Cute, how he explains and check everything is fine or not😅😀
Nice! Keep up the good work😊✌️
Hi Akshay, Thanks again for your great tutorial!! Could you make a video on ReactJs or NodeJs if possible.
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 🙏🙏
typeof(object) and typeof(array) would be "object" it self. How would we solve that edge case ?
Array.isArray(arr) would return true for an array.
I used this --> if (typeof obj[key] === 'object' && !(obj[key] instanceof Array))
@@PushpakB541Array.isArray()
the Vedios are very good......Sir is there any pdf or word format document to entire vedios.(like to remember explanation)...?
Good to see u on utube bro..😉 all d best ..👍 #akshay #vivekgoyal
Hi Vivek, Thanks a lot. It's great to see your text here. Ping me on WhatsApp, I lost your number. 😊👍
great explanation....
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.
Thanks for this video and please make more such videos related to solving programming questions
Nice one..also do one video for performance tuning in JavaScript..thnx
nice explanation Akshay... why don't you write the code on EDITOR after the explanation instead of board. This will solve the space problem.
enjoyed a lot
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
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.
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.
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
@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"));
@@ManvendraMaan I'm getting Range error Call stack size exceeded
@@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));
Thank you so much for explaining this problem
great explanation !!
Great video, Please also come up with some DS and Algo videos.
I thought of using stacks for saving the intermediate object states
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) {}
You're a champ! 🔥
😃🙏
Thats why I read comments 👌🏽
Hello Akshay Sir, would you please discuss on GENERATOR Function and Async Await in details? Please?!
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.
Nice video but I had to watch it in 1.5x, :)
awesome ❤️
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"))
nice bro
The way you teach from ground up, is really awesome. You should use RUclips 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 !!!!
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.
@@akshaymarch7 That is really nice and great intention. Best wishes and i am a subscriber already. And yeah do catch some sleep.
thanks a lot for this knowledge.. It is very helpful !!
We can also use for of loop ?
What if there is an array value , because typeOf(array) is also a object right
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.
did you get answer to this problem
Hi bro, I would like to request if you are free plz make the React js all concepts tutorial for your Juniors. Thanks
Hey Akshay I am thinking about those who dislike this video. They will punish by garun puran law.
#CheersAkshay
Hahaha 😝
thank you
What id I don't want to use global variable finalObj. I just want my function to return final destructed obj?
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 ?
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.
Human generation is a recursive process. Father (A Human) --> Son (A Human) ---> Grandson (A Human) ---> ...
I do not understand how the functions goes to office object after personal obj , could anyone explain what happens over there ?
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
If(typeof(obj[key]) ! =object && ! Array. IsArray(obj[key]) this would be more guarded case
Solved it in 15 minutes only. : D
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;
}
Bro tell me in case of array of objects
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.
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 !
Got a max call size exceed if i used Object.entries. Didn't get why.
hI bro can you explain about event looping in javascript?
05:26 I thought you have two thumbs like Hrithik
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?
@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.
Can we have a deep knowledge of JavaScript to learn Reactjs .
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 .
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
Here for the thumbnail
29:50 how it will go there
Can anyone explain how
1+[4] returns 14 I don't get this
I'm getting range error Maximum Call stack size exceeded
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
i had same problem so i thought wrapping input in another object and use for in to get key name