JavaScript Mock Interview | Online Interview Questions and Answers

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys so today I'm starting a brand new series on mock interviews and this is where I get to interview one of you my audience to see how you perform under pressure and today's video was recorded about a month ago and one of the volunteers is my subscriber and it was great you know it was a one-hour interview and it was a JavaScript and trick let's check it out and again if you want to be in the hot seat and you wanna meet you if you want me to interview you feel free to contact me I'll provide an email address here and also in the description especially if you are currently interviewing company this would be a great experience for you so you know practice before you go do the actual thing and welcome to tech see tutorials so let's start with understanding you said your level is medium right so if I give you like a 1 to 10 what would be and so tell me a little bit of a buttock to your experiences with Chelsea what have you done so far and then I discovered some YouTube channels and got a little more into web development great great I think it's important I think it's more important than I have a career because a lot of people make a career choice as a job you know to program and then they don't have passion but it seems like your passion and which is important okay all right so let just gonna start I'm just gonna type here and then let's say if I have and are you familiar with the latest es6 syntax okay so here I have an an object well is one similarly I have this too and so what I want to do is take this object so you can write a function or some you know Horsham or some way to translate this object into an array where array would only contain the values of you know so should have one and two as the elements you're almost there but I think entries would give you like a sort of like a two dimensional right all I need is just some values like one and two okay so let's do this it's gonna create an empty array and then loop through the object and I believe um should put all the values into that array okay and sorry let me just yeah okay let's say you have a string and I want it to convert into this string which would be reverse well how would you do that so x2 y2 we factor that just assume that s and then just to make sure that works your first string X and just to make sure that it works we can and I mean that's that's gonna work as long as the as long as everything is lowercase we want to take into account the potential of having uppercase values and the array in the string that we're passing in then you know the algorithm would obviously be different all right let's move to the next question let's say you have an object which is pretty much the same as before one and then you you have get a method which nothing but just console logs it they start a okay and there is another method called get B which does the same thing and yeah it's really it's very difficult to type in here but anyway okay so now what if I want to do something like this where I can call a and then get B and this should print both console logs so what modification can I make in this code such that I would get the desired result so just to clarify what you're looking for is a way yes so it should run when I when I run this statement object get a dot get B they should first print you know the value of a which is 1 and then 2 in a console looks like you'll get an error on that 114 over there I get an error from the way I understand it yes well you would not get yeah so you would not be able to run get B yes that's going to console.log what that is right so what would you change so that it would want to console both values no so I don't want to change okay so I don't want to change the line 14 in any way I want to keep the line 14 as it is however you can make the change the object yeah - 2 - so that there won't be any error on line 14 that should do it that's right yeah because you're returning into our object backs I should know that is a that is a solution out of mine yet now I'm moving to level 7 okay as as per my level okay my understanding of level it's gonna get a little bit tough but seems like you doing good let's say if I have an array I want to have a method called print' okay which basically prints so you want to print the elements of the array yeah right now if you run this it would not work obviously so how would you do that I think I see what you're looking for we want to do rate prototype rent equals [Music] I'm not I'm not fully confident in this answer I'm going to test this out and see if it works okay this will of solution obviously be only if it has the aesthetic to elements and I could modify it to have more because that's the right solution yeah it will weren't in this case because you have you know two elements do you want what if yeah let's say yeah okay [Music] an extra work I kinda cracked yeah that should work there's a one caveat though that it would what it would do is because of the comma at the end of the each element you would get an extra comma I believe yeah okay so I can correct you know but the simpler answer would be simply convert the object to a string I think that just simply does that so if you pass it to a string constructor this I think it converts into a coma yeah comma separated values yeah okay say if I have an object called object called a equal to it is a function and it has some value and all it does is based on X equal to X and then say I have another object Y and this dot y equal to Y in the end I want to create that's a new be equal to new be right with and what this should have actually x and y so something like this okay and this boat a and B should have mattered matters to get basically getters for X so it should have gathered for X and B should have a getter for y so I can in the end I can when I do let's say get X I should be able to get the value X here which is this and similarly I can get Y as well we get Y and I want you to use inheritance to do that x and y yeah so I want you to fill in the gaps for example so a would have only has property X right be basically inherits properties so think of a as a super or parent constructor in this case and B is a child constructor somehow if you can inherit property of properties of a so you don't have to do this dot X equal to X inside B also have two methods get X and get Y no you you will that's what I'm saying if you look at the line 4:15 I am getting I should be getting getting X out but it should be not it should not be setting inside like this dot X dot equal to X it should be using a to set that as you know like if you in Java or even Jaws jaws could be a super right similarly not X were you looking for something like that I'm not so used to the non classics class in text oh I think this should work right this should work the only problem is well this should not work on one line so line 10 won't work because in order for you have not initialized a like you know a just a function right so you won't be able to get the property since I say let me just think that through before I finalize that I think that'll work yeah that would that would work this you know the intrud of doing it new here you can simply use call to you know copy you familiar with call function right okay yeah so you can do you can do so here you can do something like this a dot call this basically yeah okay yeah and and you can and you don't have to do this X here you can simply do a dot type equal to basically yeah like this and then you can similarly you can well you can have Y inside is fine because you don't you know inheriting further but then no you don't have to yeah so there's one more but yeah there's one more thing you have this set the constructor but yeah but you should work here another one this is a little bit interesting let's say if I have Const object equal to I have a which has be and which as C equal to 1 something like now how do I so the problem with this if I want to clone this object so I I want to create another object where let's say I I create another object called Cologne okay by doing something okay that you can figure out but ultimately what should happen is if I do let's say clone dot a dot B dot C equal to 2 and console.log let's say object dot a dot B dot dot C it should not give me to know so first of all just let's think of this way how would you come on it first of all basically create a create a copy so that it's not linked to the original object it has its own I mean it it looks the same but it has it has its own value so if you change the clone it doesn't impact the the original object I know so the sort of syntax of particular design is you would have like an empty object and then you take the the object in pass inter yeah but it's a tricky question because it sells it does create a clone technically but it's a shallow clone yeah so what I was saying is that the object assigned would work only if it's like a one level deep object because it still doesn't let go off the reference because if you look at here B and B actually is an object C is actually primitive value so it doesn't keep the reference but B would keep its reference because here you're only kind of fixing a in a way right do you see any do you see any other possibility that that you can do so basically the answer is deep cloning I'm not sure okay all you do is well what solution is to you can you can write something to occur see where it just goes deep and just keep copying okay and so then you copy literally everything so there's no reference attached to the original object another solution would be and this is a hack I don't think you can use it and the way it works is you can do for example you can take an object Jason dot stringify object when you do this basically converts to a string right so there's no reference left and then you can do jason dot parse and that would basically create a new object it's a simpler solution yeah yeah it's a hack yeah if it's a if it's not a deep too deep for an object you can do it because a speed wise I think I haven't looked at the performance of this if you have a giant object you might have you might have some implications but this works actually okay actually I had created the only this many questions I thought you would take one hour but you're speeding through so that's great actually okay so let's say if I have an array a equal to XA 1 2 5 7 & 9 & I mean that's just give you an example but it could be much longer erase what I what I want you to do is create another array called C which would hold you know which would merge this to erase so it would be like a keep s wanna yes keep it sorted as well I think that shouldn't work if I remember correctly okay so let's look at it you have to a plus B I mean I know you can use an cat but I think using an addition operator on our way we'll just merge them is that correct no so what addition operator would do is it would do something so since the last element of not a is 9 and the first of element of B is 2 it would do to something like this so you would get a 92 in between yeah that should just return array and then I can start it right okay yeah that should work B okay so let's look at the let's see if if if one of your array is just just really large sorting you would you would kind of need to do unnecessary sorting is there any simpler way of is there any better algorithm that would help you do that to maybe a nested loop and loop through and then put the elements of the second array into you like a binary search and put them in to the correct place in the new array but I don't know I mean I guess we can test if I don't know that that will be faster than the solution okay was that what you had in mind well simpler solution in the terms of number of lines is the one you have right now but what I was looking for is optimal solution so faster it this this works in this case because it's not many elements but if you have much larger set of elements the sorting becomes unnecessary yeah one way to do it is do you think any any different I mean you don't have the code it just if you can walk me through by just looking at the numbers how to put them in in a sorted manner for example let me give you a hint right let's say if there there were a million B is like million long and eighth has like five elements right now if you concat them and sort them sorting basically it's a dump sword right so we'll go through every single element to to sort this right the trick is inside how you do it if you were to do it like a manually I always want when I somebody asked me a question you know usually I try to do things and manually by just looking at things and see if it makes sense so if you have to manually do something how would you do it so I look at the first element in beat yeah see we're we're in a I should place it which would be after the second element the next element would be after the fourth element once I have the two in and so on and so forth yeah so yeah so the answer is basically you take first elements of each so you would have two pointers basic okay you you been pointed in the sense you you keep track of index of each other you create two indexes pointers which tracks index and then you start from the first element one so here you have one and two right so you say which one is the smallest and so the one is a smallest so you push that a to another array then you still keep so then you move which already pushed you move that index to to implementing index so now you're comparing A's to to B's - now here you have the same so you can pick any you can make that decision right and then let's say let's say assume that you you you picked two from the B now you increment the index so now both indexes like 1 1 right so you could then you compare 2 to 5 and then you put 2 so by the time you reach 9 you're kind of done right then you you know that you've done with a then you just take whatever you have in B and then just push it into the to it so you you know like maximum 5 comparison and you done yeah so that's that that's usually the the there are actually a couple of other solutions to that but again I think most of the interview or accept that solution as are on that that solution will definitely be faster assuming that a is not sure than B but let's say yes with that solution so be performance efficient solution yes because think of the this way right so let's say B the length is n right so in here you are comparing two LM so maximum you're comparing n times or like 2n right in this simpler solution you have to concur which is not that so Khan getting actually is you you know Kincaid is not a big but sorting if you look at the even the fasted sword which is let's say quicksort right which is I think I believe n log n so it's yeah so 2 n is yeah better than n log yeah so that's how all right so let's do one last and then we can let's say you have the same way X equal to one then you get X here and inside executing this so here so in this case if you get object get X what will be the answer what would you get just make sure the scope make sense so just get X to create a constant called inner which will console.log this dot X and then I call inner so X should give you one if I'm understanding this correctly okay well okay so it should give you undefined yes I figured I was making their answer yes so the this that X will be undefined because this is well it's not going back up to the object it's gonna reference the the function at its head yeah so what are the I'm sure you you know the solution to it but what I want you to do it is to come up with the multiple solutions how many ways it gets all this so that I would get one as the answer while keeping the same function structure so yeah you can you can change if we that should that's a one solution but let's say yeah so that's a that's the best solution what are the other so let's say if you want if you want to keep that as a function for example let's say when you in a Babel right that the error function get compiled to you know regular function right in that case how how would that how would they deal with this kind of situation yeah because I kind of just use those arrows no I think you made a right decision to move to you know move to an arrow directly [Laughter] think of another solution right now off the top of my head I wouldn't be able to call object right no not not from insight I'm not sure okay so one solution would be here let's say if you have like a regular function right then you can do one thing you can say kant's that equal to this and then you can just because of the lexical scoping so because you're not using this here right so it should work another solution would be that's if you want to keep this as right then you would do call on this what do you think I mean I based on the entry I would say you are close to close tonight and I'm just comparing with a lot of you know other people that I've interviewed so far you know you know you not only just have a solution with you you were quick on your feet for me even though I collaborate it doesn't form a do you format it you know so you provide the tabs and everything which is also very important because I'll have people who just doesn't do that and just write everything in one line that is why I use collaborate because I want to see how they actually code yeah you have the knowledge and skill and passion all right all right so that's about it I hope you really enjoy the interview and if you did please like subscribe and provide nice comment and if you want to be interviewed again you can contact me here provide here at this email address and remember I'm not gonna disclose any name or anything so your identity would be undisclosed also you can help the channel via patreon truly help me by watching the advertisement which would be followed after this video and thank you
Info
Channel: techsith
Views: 113,467
Rating: 4.9289269 out of 5
Keywords: interview questions and answers, mock interview, mock interview practice, online interview practice, mock job interview, interview preparation, questions for interviewer, javaScript, programming Mock interview, techsith
Id: OOC-ypVnHAY
Channel Id: undefined
Length: 41min 45sec (2505 seconds)
Published: Wed Jun 13 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.