Тёмный

Google JavaScript Interview With A Frontend Engineer 

Clément Mihailescu
Подписаться 533 тыс.
Просмотров 206 тыс.
50% 1

In this video, I conduct a mock Google JavaScript interview with a frontend engineer, Conner Ardman, who's also the FrontendExpert course creator and an ex-Facebook software engineer. As a Google Software Engineer, I interviewed dozens of candidates. This is exactly the type of frontend JavaScript coding interview that you would get at Google or any other big tech company.
Check out the React interview that we filmed on Conner's channel: • React Coding Interview...
AlgoExpert: www.algoexpert...
SystemsExpert: www.systemsexp...
MLExpert: www.algoexpert...
FrontendExpert: www.frontendex...
ProgrammingExpert: www.programmin...
My LinkedIn: / clementmihailescu
My Twitter: / clemmihai
My Instagram: / clement_mihailescu
Prepping for coding interviews or systems design interviews? Practice with hundreds of video explanations of popular interview questions and a full-fledged coding workspace on AlgoExpert - www.algoexpert.io - and use the promo code "clem" for a discount on the platform!

Опубликовано:

 

25 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 259   
@clem
@clem 2 года назад
Be sure to check out the React interview that we filmed on Conner's channel! ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-5xf4_Kx7azg.html
@PSSMPlay
@PSSMPlay 2 года назад
Hey Clement, your deepEquals function also does not work on all cases because the Object.keys() array is not ordered. Therefore you could have the same object {a: 1, b: 2} and {b: 2, a: 1} throwing false. The only wall to deepEqual objects is to use a Set and compare the size to both the object's keys and then iterate the set.
@gaurabsubedi3579
@gaurabsubedi3579 2 года назад
Hey Clement, do I get the opportunity to have a mock interview with you on AlgoExpert?
@anshujindal3694
@anshujindal3694 2 года назад
@@PSSMPlay I actually wrote the same comment and later found out your comment here 😅. I think I am not the only one who was able to come up with that bug 😂
@SportFusionYT
@SportFusionYT Год назад
deepEquals utility function was fun to watch. Though there is a failing test case. { a: 1, b: 2 } === { b: 2, a: 1 } should return true. Instead of checking equality of key arrays, we can do the following - for (let i in value1keys) { if (!value2keys.includes(value1keys[i])) { return false; } }
@ConnerArdman
@ConnerArdman 2 года назад
Thanks for having me back on! These questions were harder than they seemed 👀
@aman.social2100
@aman.social2100 2 года назад
Especially the 2nd one 😅
@ManoToor
@ManoToor 2 года назад
Does your deepEquals work with functions or classes?
@thedevnoteyt
@thedevnoteyt 2 года назад
I have been doing JavaScript for last 9/10 months, after watching 8 mins of your video I realised that, still there are thousands of things to learn in JS. Going to re-learn the important concepts again 😅. It was kind of an eye opener for me. Thanks Clement 😉
@red_boum
@red_boum 2 года назад
Promises are usually more difficult for front-end devs because we only use (async await)
@UrbanJackJr
@UrbanJackJr 2 года назад
​@@red_boum but these are still promises under the hood.
@thalibmuhammad9519
@thalibmuhammad9519 2 года назад
ive been doing javascript react for 5 years and i still have same feeling as you
@thedevnoteyt
@thedevnoteyt 2 года назад
@@thalibmuhammad9519 Thanks for your reply , it is giving me a little ray of hope ! 😅 Maybe I'm still at a very early stage of learning JS. It'll take time ig 😄
@thedevnoteyt
@thedevnoteyt 2 года назад
@@red_boum that's true 😅
@universecode1101
@universecode1101 2 года назад
As a Js - React developer, I am always ready to see this type of content, because it is clean, it keeps me trained, I improve, and even fun 😜
@doublegdog
@doublegdog 2 года назад
Actually tried out algoexpert after seeing ads on youtube for over a year. Thought it wasn't anything special but the platform plus the blind75 leetcode questions really helped me out in landing a job at amazon!! Definitely recommend the platform although I wish I didn't have to pay a yearly subscription fee and instead had a monthly option. But still, i think even the yearly subscription is affordable enough.
@RealNsiem
@RealNsiem 2 года назад
did you do the blind75 on algoexpert or do you mean the blind75 leetcode questions AND the algoexpert questions is what helped you?
@HarukiMiyazawi
@HarukiMiyazawi 2 года назад
After failing google on site and seeing Clement's amazing problem solving skills, it's clear to me why he got the job and I didn't. You're awesome dude!
@kelvinxg6754
@kelvinxg6754 2 года назад
stay faithful brother keep up the work you'll get there.
@technologykid7041
@technologykid7041 2 года назад
don't worry google is notorious for hard coding interviews, you got this! Stay motivated
@hovarda0655
@hovarda0655 2 года назад
We are all gonna make it brah
@alexandrsachishin962
@alexandrsachishin962 2 года назад
13:00 better approach is to use Number.isNaN() instead of isNaN() to check if a number is NaN. also this comparison might be simplified using Object.is(valueOne, valueTwo) which also works with NaN ( Object.is(NaN, NaN) )
@deepakjangid3872
@deepakjangid3872 2 года назад
Today I had an interview and there we exactly these two promiseAll and object deepEquals, and now after the interview I am watching this.
@AWPNATiCTV
@AWPNATiCTV 2 года назад
To fix "problem" that you guys had at 12:00 with the isNaN function not returning what you would expect, you now (since es6) have the method Number.isNaN(), that only returns true if the value is actually NaN. The isNaN function returns unexpected values because it tries to convert the value to number and then check if it is NaN. Since strings that are not the empty string are coerced to NaN when converting to number, isNaN("some non-empty string") runs as isNaN(Number("some non-empty string")) == isNaN(NaN) == true. Number.isNaN checks if the value is of type number first and returns false if it is not, an then checks for NaN.
@howuseehim
@howuseehim 2 года назад
Where did you learn all of that 😃
@nekiro894
@nekiro894 2 года назад
@@howuseehim in a book I believe, that's a great source. Javascript does all sort of blind conversions on values to ease equal checking
@SafetyLast-_-
@SafetyLast-_- 2 года назад
Exactly! I also wanted to write a similar comment about wierdness of isNaN(). And that Number.isNaN() is much more reliable in that type of checks :) Searched for this comment to not duplicate and if here it is! 👍
@gardelin4793
@gardelin4793 2 года назад
@@howuseehim Probably in You don't know JS book
@howuseehim
@howuseehim 2 года назад
@@gardelin4793 thank you I will check it out
@MrKanthappu
@MrKanthappu 2 года назад
He didn’t apply for google and you aren’t interviewing for google. So stop saying google interview
@anshujindal3694
@anshujindal3694 2 года назад
I think deepEquals function would fail one edge case by doing the last change if obj1 = {b: 2, a: 1}; obj2 = {a: 1, b: 2}; because Object.keys() return the keys in insertion order and upon calling deepEquals again, it would be ['a', 'b'] and ['b', 'a'] and it would get failed while checking if 2 arrays are equal or not and in actual library it would return true.
@Krzysiekoy
@Krzysiekoy 2 года назад
The deepEquals question reminded me of a similar problem in the Dan Abramov's Just Javascript "course" (it's not really a course, but I don't know how to describe it). Basically the problem was: "Write a function called strictEquals(a, b) that returns the same value as a === b. Your implementation must not use the === or !== operators." It was a fun problem, especially when you consider some details that are not super obvious, like 0 === -0 is true or NaN === NaN is false. Now, the deepEquals question seemed to be way more challenging and it was great watching Conner go through the problem.
@aaronmark3930
@aaronmark3930 5 месяцев назад
use bit operators
@covle9180
@covle9180 2 года назад
Love this video! I think with the deepEquals function there were still 2 unsolved edge cases. (But I'm happy to he corrected) 1. The order of object.Keys isn't guaranteed to be sorted, so the deepEquals check to make sure the same keys exist could give a false negative. 2. You can get endless recursion when an object contains a nested reference to (part of) itself.
@valseedian
@valseedian 2 года назад
came here specifically to make these two points.
@unorevers7160
@unorevers7160 2 года назад
100% correct
@nickrobinson6434
@nickrobinson6434 2 года назад
The key order issue also caught my attention. The problem is, in JavaScript, key order is never guaranteed. The lodash isEqual function does not account for key order either. _.isEqual({ "a": 0, b: "1" }, { "b": 1 , "a": 0 }) returns true;
@GeekyAdarsh
@GeekyAdarsh 2 года назад
for #1 we can use hasOwnProperty method
@sadramohh
@sadramohh 2 года назад
About 1. Does the order really matter in objects? Two objects with exactly the same keys and same values for those keys behave exactly the same regardless of the order their properties were added. Is there a case where the order of keys is actually integral to a programs functionality? About 2. Totally agree.
@BGivo
@BGivo Год назад
That was sick.. I didn't realize Clement was so good holy jesus
@shaileshk_gy
@shaileshk_gy 2 года назад
Thanks for this. This actually helped me learn a lot of things I never knew.
@TheDoubleMvp
@TheDoubleMvp 7 месяцев назад
Great questions, definitely representative of the sort of questions you'd be asked in a big tech FE interview. Conner did awesome as well, solving all 3 with clean code in < 1 hour in an interview would be an easy yes from me.
@AndrewTSq
@AndrewTSq 2 года назад
I did not think this video would give me so much, cause I am not so experienced in JS, but I actually understand how the functions works, and know the functions we use. So its fun to follow with this, and also learn what these functions do :)
@yanwei6677
@yanwei6677 2 года назад
Great video For the 2nd question, we compare objects based on ValueOne's keys. And if we compare them again on ValueTwo's keys but not deepEquals(keys1, keys2) like the video did, will it work? I believe not, it will failed by this case: {a: undefined, b: "str"} {b: "str", c: undefined}
@farazcsk
@farazcsk 2 года назад
Great video! Would also love to see a standard algorithms/ds video but in JS
@sotam8938
@sotam8938 2 года назад
agree!
@chrtravels
@chrtravels 2 года назад
I have been learning to code for a couple of years now and watched some of your videos back when you first launched Algoexpert. I hadn't looked at your website in some time and man is it super impressive. It has a clean and beautiful design. The curriculum and topics you cover is incredible. What an excellent business you have created. Bravo. I kind of wish I hadn't spent so much money to join a boot camp recently. I'd just go and learn everything you have on that site, build a few projects and call it a day! ;-)
@canonicalbogdan
@canonicalbogdan 2 года назад
24:30 -> The order you get properties is a complex topic in JS. To have a general idea about it: Before ES5 there was no order defined for iterating objects. Here came ES2015 and there was a order defined in certain situations(Object.assign, JSON.parse, JSON.stringify, etc.) and the order followed this pattern: integer keys -> ascending order string keys -> insertion order symbols -> insertion order ES2020 came with changes for Object.keys, Object.entries, Object.values. In conclussion: if you had es2020 you could have used Object.entries for that. Peace
@bahadrtaspinar4575
@bahadrtaspinar4575 2 года назад
my man getting faster in each video while promoting algoexpert
@clintondannolfo714
@clintondannolfo714 2 года назад
I didn't watch the full video but perhaps the function "getTimer" could use "getter" methods on JS classes to always provide the most up to date value based on the current time, without having to use setInterval
@somnathnavale9120
@somnathnavale9120 2 года назад
for second question we can use another approach like serialized both the inputs using JSON.stringify() then make strict comparision """ let a1=JSON.stringify(input1) let a2=JSON.stringify(input2) if(a1===a2){ console.log('they are deep equal'); }else{ console.log('they are not equal'); } """ using recursion """ function deepEqual(obj1,obj2){ if(typeof obj1===typeof obj2 && typeof obj1!=='object'){ return obj1===obj2; } if(typeof obj1!==typeof obj2){ return "can't compare different types" } if(!Array.isArray(obj1) && Object.keys(obj1).length!==Object.keys(obj2).length){ return false; }else if(obj1.length!==onj2.length){ return false; } let ans=true; for(let key in obj1){ ans=ans && deepEqual(obj1[key],obj2[key]); } return ans; } """ comment if I made any mistake or not added any edge case
@Kay8B
@Kay8B 2 года назад
The problem is objects order can be all over the place, once you stringify it the order is locked and although two objects maybe equal the order isn't and returns false but its technically true.
@UnimpressedCat
@UnimpressedCat 2 года назад
Nice interview, the questions are quite practical and test the knowledge of the language. And damn, the interviewee is quite good at catching edge cases and clues from the interviewer
@keirangrant3706
@keirangrant3706 Год назад
As a 25 year old who just started learning to code, this made my brain hurt 😂
@Endrit719
@Endrit719 2 года назад
The fact that you caught the undefined case blew my mind, and in the updateTimer it fckin blew my mind again, I don't even understand why it is working
@dmytrochornyi5249
@dmytrochornyi5249 2 года назад
For the second problem, just compare the types first and then compare JSON.stringify of two values, not sure about speed, but covers most of the cases
@dontbetoxic4387
@dontbetoxic4387 2 года назад
thats what i thought too
@kubrd1921
@kubrd1921 8 месяцев назад
JSON.stringify is sensitive to the order of properties in objects. If two objects have the same properties and values but in a different order, they will be considered unequal.
@jordanbarone9094
@jordanbarone9094 2 года назад
New JS developer (about 6 months) looking for an entry level position...after watching this, I am now extremely scared for an interview lol...Very intimidating! Great video though!
@Ibrahim__123
@Ibrahim__123 2 года назад
Just to add Object.entries() one can rely on the array it's return...I read about it just now while watching the interview ...Welldone guys....Super....
@mstalcup
@mstalcup 2 года назад
The problem with using isNaN() is that it forcefully converts the passed parameter to a number before evaluating it. A better way to check for equality is to use Number.isNaN(). This returns true only if the parameter is of type number and actually equates to NaN.
@nivelis91
@nivelis91 2 года назад
21:00 you could use an XOR "^" operator instead of OR "||" :) You also forgot about 0, -0, Infinity and -Infinity - but it's arbitrary whether they're treated equal or not. "===" will say yes, Object.is() will say no. Aaaand there are functions too ;)
@aaronmark3930
@aaronmark3930 5 месяцев назад
was thinking the same with xor, but since he checked a === b before the || call, it doesn't matter to use xor or not
@mkurshumov
@mkurshumov 2 года назад
Why not use JSON.stringify(valueOne) === JSON.stringify(valueTwo) for comparing non-primitive values
@jpborges
@jpborges 2 года назад
If we are going down that route, might as well stringify both objects and return in one line
@hicoop
@hicoop 2 года назад
Watching this video with the javascript console open and my mind completely blown
@EllieP-c7s
@EllieP-c7s Год назад
Thank you for the video, I learnt a lot. However, I think there is an edge case for the second question, lets say : const obj1 = { a: undefined , b: 2} const obj2 = { b: 2 , a: undefined } with this code the output of deepEquals (obj1 , obj2 ) will be false. whereas it should be "true" I think instead of deepEquals (valueOneKeys, valueTwoKeys) in line 31, a better approach would be to iterate through valueOneKeys and if the item was not found in the valueTwoKeys then return false. for (let i=0; i < valueOneKeys.length ; i++){ if ( valueTwoKeys.findIndex (element => valueOneKeys[i] === element) === -1 ) return false }
@lucasrgsilva
@lucasrgsilva Год назад
For the 1st question you can actually use async await in a for...of loop, because all promises are in the pending state, doing that if the first one takes longer, the others will be completed when you reach them in the loop.
@jesseliverless9811
@jesseliverless9811 2 года назад
12:12 isNaN(x) returns if the value of x is 'NaN', *after conversion*. So in your example, isNaN('aaa') returns true, because of course it is, the string 'aaa' is not a number, so there's no problem here. The quirk is when you test isNaN(" "), it returns false, because it converts " " (or "") to 0, which is a number, so isNaN(0)=false. Same goes for strings that get interpreted as numbers, so isNaN("3") ==> isNaN(3) ==> false. This behaviour might be unexpected if you're unaware of the implicit conversion.
@ScorpioneOrzion
@ScorpioneOrzion 2 года назад
For that of deepEquals their is one situation missing const obj1 = {a:1, b:2}; const obj2 = {b:2, a:1}; console.log(deepEquals(obj1, obj2));
@timmoser7093
@timmoser7093 2 года назад
At 37:50, if you run deepEquals on the keys too, it would return false on two objects with the same entries but in different order or am I missing something?
@brianarsuaga5008
@brianarsuaga5008 2 года назад
38:35 deepEquals'ing shouldn't work, should it? Because Object.keys isn't guaranteed to give the same order between two objects, unless you actually intend for deepEquals to respect insertion order. Also, since object keys can only be strings, you're definitely doing too much work with deepEquals on the key lists. Example: obj1 = {a:1}; obj1.b=2; obj2= {b:2}; obj1.a=1; This yields something like {'a': 1, 'b': 2} and {'b': 2, 'a': 1}, which I assume should be considered equal here. This should either by hasOwnProperty or maybe obj2Keys = new Set(Object.keys(obj2)); if(!obj2Keys.has(key)) return false; Though I'm skeptical that the set operations will end up faster in practice than hasOwnProperty.
@321123580
@321123580 5 месяцев назад
Super helpful interview, thank you for the content
@thehierophant1314
@thehierophant1314 2 года назад
I just realized that coding logic is so hard because the interviewer also has to understand what the guy is doing 🤭 when he asks him questions and then he says, “oh okay I see!”
@YoriDj
@YoriDj 2 года назад
I want to see the center a div interview with a frontend engineer
@ДиванныйМонстр-ъ8с
If you rely on order, than JSON.stringify(a) === JSON.stringify(b), in other cases, just use lodash )))
@unorevers7160
@unorevers7160 2 года назад
Im pretty proud that I spottet the edgecase where the value 'undefined' of an object is compared to the undefined value of an unfound key in the array that was compared against. Then again while I thought about comparing 'undefined' I forgot about how JavaScript also has 'null' objects :'D
@rnater7145
@rnater7145 2 года назад
Symbols are possibly another edge case
@felixc.programs8209
@felixc.programs8209 2 года назад
Good video as always! You motivated me to start my own Data Science/Engineering RU-vid channel myself. Can't wait for your future content!
@Daneus_GMD
@Daneus_GMD 2 года назад
34:36 my head almost exploded here
@ozzyfromspace
@ozzyfromspace 2 года назад
10/10, wonderful interview. Interviewee did really well imo
@arifozturk5972
@arifozturk5972 2 года назад
For the second question, wouldn't it have been way easier to stringify the objects and then check the strings and the types match? I.e. JSON.strinigify and typeof equality
@blackstratmx
@blackstratmx 10 месяцев назад
I was thinking in some sort of binary check but not possible in JS, I think you are totally right!
@pranavyeole102
@pranavyeole102 2 года назад
Hi Clément, can we get the prices of Algoexpert products in Indian rupees and an option to purchase the product with UPI (widely popular in India). Algoexpert is getting a lot of consideration from engineering students here, and making these changes will make Algoexpert a lot more accessible to Indian students. Please do consider this request 🙏🏼
@kumarsamaksha7207
@kumarsamaksha7207 2 года назад
Just pay using card
@memoryleakerz
@memoryleakerz 2 года назад
Hey Clement! Wanted to ask about the Big O for time for deepEquals, is that O(n) right? I'm currently taking a course for algo's and data structures and just wanted to ask you thattt
@anthonywalker6168
@anthonywalker6168 2 года назад
Google has turned into an ad search engine. When I search for something, I don’t want to be followed around my a man ad. Definitely investing in an ad blocker
@msx47_
@msx47_ 2 года назад
You didn't need it but to check for object you can use something like myVar.constructor === Object or for array with myVar.constructor === Array.
@yechielvizel
@yechielvizel 2 года назад
I thought about the undefined edge case the second he said “will give you undefined”
@starlingroot
@starlingroot 2 года назад
Quality content as always
@anupmahato6163
@anupmahato6163 2 года назад
Wonderful interview. @Corner Ardman I think one edge case is missed in PromiseAll problem , when you don't pass any promise to PromiseAll function.
@McScraych
@McScraych 9 месяцев назад
Regarding the second task. Why check arrays separately? (I think that the "Object" code worked properly for the arrays). Why didn't write tests for all the types? Also what regarding different class instances?
@mag2XYZ
@mag2XYZ 2 года назад
The first one is not correct, as one can add elements to the array while the Promises are running, which makes the condition to exit impossible. It can be fixed by storing the starting length of the array in a variable at the beginning of the function.
@melanineyedoc
@melanineyedoc 2 года назад
I got an algoexpert ad on this, with algogirl too!!!!!
@goodrowj
@goodrowj Год назад
You guys forgot the case of either object being a function in deepEquals
@HeinekenLasse
@HeinekenLasse 2 года назад
38:00 - Don't you need to sort the keys to run a deepEquals on them ?
@Krilllind
@Krilllind 2 года назад
For the `updateTimer` function I miss a discussion regarding time drift when using setTimeout. This HTTP 203 episode (ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-MCi6AZMkxcU.html) talks about how to optimize for drift. Otherwise, good episode! One thought, could you not make use of `setInterval` as well in the sandbox area? And use a `clearInterval` with `setTimout` to perfom cleanup?
@thekwoka4707
@thekwoka4707 2 года назад
For the second, why did it not just start with a strict equals check? Surely if they are strictly equal, then they are deeply equal too.
@akshaysharma30498
@akshaysharma30498 7 месяцев назад
For checking between array and object, woouldn't checking if 'length' property exists on one and not on another work ?
@GabrielCrowe
@GabrielCrowe 2 года назад
Serious question: Why is this not appropriate for deepEquals? const deepEquals = (object1, object2) => JSON.stringify(object1) == JSON.stringify(object2);
@pipitgusmayanti8342
@pipitgusmayanti8342 2 года назад
JSON.stringify can only serialize null, Boolean, Number, String, Object, Array. The 'toJSON' method of an object is used to implement custom behavior when serializing the object. JSON.stringify(undefined) returns undefined, JSON.stringify(1n) throws a TypeError, value that cannot be serialized properly is serialized as "null" or ignored when used as the value of a property. JSON.stringify({ a: undefined }) === JSON.stringify({ a: undefined, b: undefined }) _// true_
@miguelpancada5873
@miguelpancada5873 2 года назад
Isn't there a concurrency bug on the promiseAll function? If promises run asynchronous, when they want to increment settledPromisedCounter, it´s possible to get a Phantom/Ghost update because settledPromisedCounter is not threadsafe, right? If 2 promises read at the same time settledPromisedCounter, they will read the same value, lets say 0, and each of them will increment to 1.
@grablecdub
@grablecdub 2 года назад
Love these
@senturkdev
@senturkdev 2 года назад
Sir, do you have a plan for regional price? I live in Turkey and your plans are almost 600-700 Turkish liras. The amount is really high for people who live in Turkey. 🙏🏻
@TheYinyangman
@TheYinyangman 2 года назад
JSON.stringify any object for comparison
@PatrickAssuied
@PatrickAssuied 2 года назад
Yep.
@dziq4549
@dziq4549 2 года назад
After checking primitive values and arrays, wouldn't JSON.stringify(valueOne) === JSON.stringify(valueTwo)? I mean when we are sure these two are objects.
@DriveandThrive
@DriveandThrive Год назад
Yeah I’d fail after the first question which pisses me off because it just shows I’ll never pass an interview. The interviewer could always just hit me with something crazy and fail me
@AshwinMothilal
@AshwinMothilal 5 месяцев назад
This was a good interview, but one confusion is, MDN says should be . Here it's . Probably might need to correct it.
@prathyushsunny
@prathyushsunny 2 года назад
15:08 - that awkward moment everyone of us faced in online meetings
@shriharikulkarni3986
@shriharikulkarni3986 2 года назад
Hi Clement, whenever interview date is near, i get stressed, i don't know how to revise, and always in my mind I'll be like preparation is not enough, and if you write a program and test cases are not fully accepted, lot of nervousness starts which will impact during the interview. How to actually stay mentally when the interview is near?
@michaelschaaf1155
@michaelschaaf1155 2 года назад
such good content. keep it goin
@RodLewis1
@RodLewis1 2 года назад
Love the content, nice work guys. Would this work for the deep compare question or am I missing an edge case? const deepCompare = (a, b) => { let aString = JSON.stringify(a, null, 2) let bString = JSON.stringify(b, null, 2) return aString === bString }
@vishmaychauhan2863
@vishmaychauhan2863 2 года назад
if the order of elements in 2 objects are not same, then it would return false. Hence it wouldn't work ig. Correct me if I'm wrong
@merlin6962
@merlin6962 2 года назад
I think it produces the correct result, but in a tech interview it wouldn't be a good solution. The interviewers want to see you implement the algorithm and explain your thoughts, not take a short cut. You could obviously mention that this would be an easy solution as well. Additionally this solution will be quite inefficient for large objects, both CPU and memory wise.
@RodLewis1
@RodLewis1 2 года назад
@@vishmaychauhan2863 you are correct, unfortunately I can only come up with a far less elequant solution in that case 🙃 const isObject = obj => typeof obj === 'object' && !Array.isArray(obj) && obj !== null; const flattenObjectToArray = (obj, parent, flatObj = {}) => { Object.keys(obj).forEach(key => { let next = parent ? parent + '.' + key : key; if (typeof obj[key] === 'object') { flattenObjectToArray(obj[key], next, flatObj); } else { flatObj[next] = obj[key]; } }) return Object.entries(flatObj).sort(); } const flattenAndSortArray = arr => arr.flatMap(x => isObject(x) ? flattenObjectToArray(x) : [x]).sort(); const handleObjectType = (x) => isObject(x) ? flattenObjectToArray(x) : flattenAndSortArray(x); const deepCompare = (a, b) => { let typeofA = typeof a let typeofB = typeof b if (typeofA !== typeofB) return false; if(typeofA === "object") a = handleObjectType(a) if(typeofB === "object") b = handleObjectType(b) let aString = JSON.stringify(a, null, 2) let bString = JSON.stringify(b, null, 2) return aString === bString }
@vishmaychauhan2863
@vishmaychauhan2863 2 года назад
@@RodLewis1 there's nothing less elequant, if it works, it works lol.
@MoulikAdak
@MoulikAdak 2 года назад
Noobs. Functions aren't handled.
@awekeningbro1207
@awekeningbro1207 2 года назад
the amount of people saying stringifying the object and equating it to the other really concerns me, no wonder why people get rejected in interviews
@mod7ex_fx
@mod7ex_fx 2 года назад
there still a problem in the second function ==> the edge case where we have to objects with same keys but the keys are in different order
@_SANDALIK
@_SANDALIK 2 года назад
seems like you forgot to check the case like deepEquals({}, []) which probably could return false on a line 11 because of typeof [] === "object" typeof new Set() === "object" typeof new Map() === "object" or I missed something?
@conceptualhandle
@conceptualhandle 2 года назад
You forgot to sort the keys before passing them to deep equals.
@karmelodev
@karmelodev 2 года назад
amazing your content.
@corv882002
@corv882002 2 года назад
Didn't you guys say that you can't rely on the order of Object.keys? Then calling deepEquals on the key arrays isn't a proper fix for the issue.
@Paladin-ev1gg
@Paladin-ev1gg 4 месяца назад
Hello. What type of "seniority" are these qeustions? As someone who's looking for a first job in coding this seems difficult.
@omgItsGreg
@omgItsGreg 2 года назад
In the first solution, you said that it's fine to use native javascript code. Then why the heck would you not just use Promise.all? There's also an issue with this solution, if multiple promises reject. You can't call the reject function multiple times.
@Коннор-ч7е
@Коннор-ч7е 2 года назад
cant beleive it so easy
@kuti1643
@kuti1643 Год назад
deepEquals could work with a one-liner return JSON.stringify(valueA) === JSON.stringify(valueB); Wouldn't that be an acceptable solution? Is there a catch to that? I've also checked with all the test cases and it works for me.
@goktugerol1127
@goktugerol1127 Год назад
They take you to the technical interview in the first meeting or they do that after the first meeting? I have a meeting soon but the recruiter didn't mention anything about technical interviews etc, they said they wanna meet me.
@kiwiate
@kiwiate 2 года назад
var assert = require('assert') const obj1 = {a: 1, b: 2} const obj2 = {b: 2, a: 1} assert.deepEqual(obj1, obj2) // passes assert.deepEqual(Object.keys(obj1), Object.keys(obj2)) // fails I think you missed a case in solution 2
@shaikzuhair8537
@shaikzuhair8537 2 года назад
Good work 👍
@leeboyin945
@leeboyin945 2 года назад
1:22 promiseAll 9:12 deepEquals 38:30 getTimer Great demo, learned a lot of tricky JS edge cases in this video! Thanks I think people are just unlikely able to remember all those weird parts of JavaScript. It is JavaScript that need improved, not developers. 🤔
@feignit
@feignit 7 месяцев назад
3rd question was really stupid, basically using an anti pattern.
@hkdragneel
@hkdragneel 2 года назад
38:00 #31 doesn't this logic fail when comparing objects having same key value pairs but in different insertion order.
@rezaroohian9549
@rezaroohian9549 2 года назад
There's a bug in promiseAll code. If a promise gets rejected we should still wait for all promises to finish since there's no way to cancel them after calling then on them.
@giovannyalbarracin1141
@giovannyalbarracin1141 Год назад
Why didn't he use promise allsettled method in the first exercise?
@deathbombs
@deathbombs 2 года назад
What is it that makes Javascript questions like these challenging, compared to say Java? Java is usually capable of doing the same stuff, just syntaxes, type checking and some edge cases are different. It doesn't test any frontend concepts?
@giorgioolivero3002
@giorgioolivero3002 2 года назад
I have a questioni about the google interview: I heard in a video that you used angular as a front-end engineer, the question is this: should I learn that before trying to get into Google? My plan was to learn to use react instead
@kilyos9212
@kilyos9212 2 года назад
It looks like the first one is incorrect for two reasons. It will hang forever on an empty array, and it will allow doubly rejected promises. Maybe I'm wrong tho. Good work Conner.
@nahfamimgood
@nahfamimgood 2 года назад
so has FANG stopped doing leetcode algorithm style questions for FE positions?
@AlexWardi
@AlexWardi 2 года назад
Looks like they've moved on to making people implement non-optimized browser functionality instead. Also silly, imo
@kevinyaya
@kevinyaya 2 года назад
Your key comparison does not work: const a = {a:1, b:2} const b = {b:1, a:2} Object.keys(a) === Object.keys(b) false yet they're the same object. You can't rely on order of keys. You can fix it by just checking valueTwo.hasOwnProperty(key) before getting valueTwoValue
@jodufan8754
@jodufan8754 2 года назад
Could nt you just use JSON.stringify for the deep Equals or would that be cheating? Just a guess??
Далее
React Coding Interview Ft. Clément Mihailescu
47:08
Просмотров 130 тыс.
Google Frontend Interview With A Frontend Expert
47:59
Google Coding Interview With A College Student
59:57
Просмотров 1,5 млн
Easy Google Coding Interview With Ben Awad
28:00
Просмотров 1 млн
5 JavaScript Concepts You HAVE TO KNOW
9:38
Просмотров 1,4 млн
Software Engineering Job Interview - Full Mock Interview
1:14:29
Google Coding Interview With A High School Student
57:24