Google JavaScript Interview With A Frontend Engineer

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ม.ค. 2025

ความคิดเห็น •

  • @clem
    @clem  2 ปีที่แล้ว +26

    Be sure to check out the React interview that we filmed on Conner's channel! th-cam.com/video/5xf4_Kx7azg/w-d-xo.html

    • @PSSMPlay
      @PSSMPlay 2 ปีที่แล้ว +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 2 ปีที่แล้ว

      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 ปีที่แล้ว +152

    Thanks for having me back on! These questions were harder than they seemed 👀

    • @aman.social2100
      @aman.social2100 2 ปีที่แล้ว +2

      Especially the 2nd one 😅

    • @ManoToor
      @ManoToor 2 ปีที่แล้ว

      Does your deepEquals work with functions or classes?

  • @universecode1101
    @universecode1101 2 ปีที่แล้ว +90

    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 😜

  • @thedevnoteyt
    @thedevnoteyt 2 ปีที่แล้ว +224

    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 ปีที่แล้ว +10

      Promises are usually more difficult for front-end devs because we only use (async await)

    • @thalibmuhammad9519
      @thalibmuhammad9519 2 ปีที่แล้ว +6

      ive been doing javascript react for 5 years and i still have same feeling as you

    • @thedevnoteyt
      @thedevnoteyt 2 ปีที่แล้ว +1

      @@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 😅

    • @thedevnoteyt
      @thedevnoteyt 2 ปีที่แล้ว

      @UrbanJackJr yeah you're right but async-await seems easy to me. Maybe I've missed a lot of the basics, I've to go through the promises again.

  • @alexandrsachishin962
    @alexandrsachishin962 2 ปีที่แล้ว +15

    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) )

  • @AWPNATiCTV
    @AWPNATiCTV 2 ปีที่แล้ว +30

    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 ปีที่แล้ว +1

      @@howuseehim Probably in You don't know JS book

    • @howuseehim
      @howuseehim 2 ปีที่แล้ว

      @@gardelin4793 thank you I will check it out

  • @HarukiMiyazawi
    @HarukiMiyazawi 2 ปีที่แล้ว +56

    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 ปีที่แล้ว +2

      stay faithful brother keep up the work you'll get there.

    • @technologykid7041
      @technologykid7041 2 ปีที่แล้ว +2

      don't worry google is notorious for hard coding interviews, you got this! Stay motivated

    • @hovarda0655
      @hovarda0655 2 ปีที่แล้ว +3

      We are all gonna make it brah

  • @doublegdog
    @doublegdog 2 ปีที่แล้ว +7

    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.

    • @TonyKeh
      @TonyKeh 2 ปีที่แล้ว +1

      did you do the blind75 on algoexpert or do you mean the blind75 leetcode questions AND the algoexpert questions is what helped you?

  • @anshujindal3694
    @anshujindal3694 2 ปีที่แล้ว +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.

  • @deepakjangid3872
    @deepakjangid3872 2 ปีที่แล้ว +3

    Today I had an interview and there we exactly these two promiseAll and object deepEquals, and now after the interview I am watching this.

  • @canonicalbogdan
    @canonicalbogdan 2 ปีที่แล้ว +26

    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

  • @Krzysiekoy
    @Krzysiekoy 2 ปีที่แล้ว +3

    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 9 หลายเดือนก่อน

      use bit operators

  • @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.

  • @TheDoubleMvp
    @TheDoubleMvp 11 หลายเดือนก่อน

    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.

  • @timmoser7093
    @timmoser7093 2 ปีที่แล้ว +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?

  • @bahadrtaspinar4575
    @bahadrtaspinar4575 2 ปีที่แล้ว +1

    my man getting faster in each video while promoting algoexpert

  • @BGivo
    @BGivo 2 ปีที่แล้ว

    That was sick.. I didn't realize Clement was so good holy jesus

  • @yanwei6677
    @yanwei6677 2 ปีที่แล้ว +7

    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}

  • @covle9180
    @covle9180 2 ปีที่แล้ว +15

    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 ปีที่แล้ว +1

      came here specifically to make these two points.

    • @unorevers7160
      @unorevers7160 2 ปีที่แล้ว

      100% correct

    • @nickrobinson6434
      @nickrobinson6434 2 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      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.

  • @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! ;-)

  • @somnathnavale9120
    @somnathnavale9120 2 ปีที่แล้ว +3

    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 ปีที่แล้ว +1

      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.

  • @mstalcup
    @mstalcup 2 ปีที่แล้ว +1

    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.

  • @clintondannolfo714
    @clintondannolfo714 2 ปีที่แล้ว +4

    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

  • @shaileshk_gy
    @shaileshk_gy 2 ปีที่แล้ว +2

    Thanks for this. This actually helped me learn a lot of things I never knew.

  • @dmytrochornyi5249
    @dmytrochornyi5249 2 ปีที่แล้ว +3

    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 ปีที่แล้ว +1

      thats what i thought too

    • @kubrd1921
      @kubrd1921 ปีที่แล้ว

      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.

  • @AndrewTSq
    @AndrewTSq 2 ปีที่แล้ว +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 :)

  • @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
    }

  • @nivelis91
    @nivelis91 2 ปีที่แล้ว +7

    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 9 หลายเดือนก่อน

      was thinking the same with xor, but since he checked a === b before the || call, it doesn't matter to use xor or not

  • @farazcsk
    @farazcsk 2 ปีที่แล้ว +7

    Great video! Would also love to see a standard algorithms/ds video but in JS

    • @sotam8938
      @sotam8938 2 ปีที่แล้ว +1

      agree!

  • @ScorpioneOrzion
    @ScorpioneOrzion 2 ปีที่แล้ว +1

    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));

  • @jbarone96
    @jbarone96 2 ปีที่แล้ว +1

    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!

  • @lucasrgsilva
    @lucasrgsilva 2 ปีที่แล้ว

    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.

  • @parkersmith7522
    @parkersmith7522 4 วันที่ผ่านมา

    38:32, I think it would fail if the keys were the same but in a different order, which is still equal objects. You'd have to compare sorted keys.

  • @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

  • @brianarsuaga5008
    @brianarsuaga5008 2 ปีที่แล้ว +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.

  • @UnimpressedCat
    @UnimpressedCat 2 ปีที่แล้ว +1

    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

  • @ДиванныйМонстр-ъ8с
    @ДиванныйМонстр-ъ8с 2 ปีที่แล้ว

    If you rely on order, than JSON.stringify(a) === JSON.stringify(b), in other cases, just use lodash )))

  • @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....

  • @HeinekenLasse
    @HeinekenLasse 2 ปีที่แล้ว +1

    38:00 - Don't you need to sort the keys to run a deepEquals on them ?

  • @hicoop
    @hicoop 2 ปีที่แล้ว

    Watching this video with the javascript console open and my mind completely blown

  • @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!”

  • @mkurshumov
    @mkurshumov 2 ปีที่แล้ว +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

  • @YoriDj
    @YoriDj 2 ปีที่แล้ว +2

    I want to see the center a div interview with a frontend engineer

  • @goodrowj
    @goodrowj 2 ปีที่แล้ว

    You guys forgot the case of either object being a function in deepEquals

  • @keirangrant3706
    @keirangrant3706 ปีที่แล้ว +2

    As a 25 year old who just started learning to code, this made my brain hurt 😂

  • @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.

  • @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

  • @McScraych
    @McScraych ปีที่แล้ว

    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?

  • @arifozturk5972
    @arifozturk5972 2 ปีที่แล้ว +1

    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 ปีที่แล้ว

      I was thinking in some sort of binary check but not possible in JS, I think you are totally right!

  • @hkdragneel
    @hkdragneel 2 ปีที่แล้ว

    38:00 #31 doesn't this logic fail when comparing objects having same key value pairs but in different insertion order.

  • @321123580
    @321123580 9 หลายเดือนก่อน

    Super helpful interview, thank you for the content

  • @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.

  • @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

  • @ozzyfromspace
    @ozzyfromspace 2 ปีที่แล้ว

    10/10, wonderful interview. Interviewee did really well imo

  • @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.

  • @NihilismEnjoyer98
    @NihilismEnjoyer98 11 หลายเดือนก่อน

    For checking between array and object, woouldn't checking if 'length' property exists on one and not on another work ?

  • @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.

  • @pranavyeole102
    @pranavyeole102 2 ปีที่แล้ว +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 🙏🏼

  • @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.

  • @leeboyin945
    @leeboyin945 2 ปีที่แล้ว +3

    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 11 หลายเดือนก่อน

      3rd question was really stupid, basically using an anti pattern.

  • @conceptualhandle
    @conceptualhandle 2 ปีที่แล้ว

    You forgot to sort the keys before passing them to deep equals.

  • @_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?

  • @RodLewis1
    @RodLewis1 2 ปีที่แล้ว +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 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      @@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 ปีที่แล้ว +2

      @@RodLewis1 there's nothing less elequant, if it works, it works lol.

    • @MoulikAdak
      @MoulikAdak 2 ปีที่แล้ว

      Noobs. Functions aren't handled.

  • @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.

  • @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

  • @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_

  • @AshwinMothilal
    @AshwinMothilal 9 หลายเดือนก่อน

    This was a good interview, but one confusion is, MDN says should be . Here it's . Probably might need to correct it.

  • @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

  • @osazi
    @osazi 2 ปีที่แล้ว

    26:58 if you had two objects with the same number of key but in different order wouldn’t that technically be true according to your your logic ?
    I might be wrong but if you have two objects and their keys are in different order but the values are the same, are they then the same object?

    • @Kay8B
      @Kay8B 2 ปีที่แล้ว

      Depends on what your after, they are not the exact same object allocated on memory etc but they are equal.

  • @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.

  • @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.

  • @memoryleakerz
    @memoryleakerz 2 ปีที่แล้ว +1

    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

  • @kuti1643
    @kuti1643 2 ปีที่แล้ว

    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.

  • @senturkdev
    @senturkdev 2 ปีที่แล้ว +1

    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. 🙏🏻

  • @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

  • @shriharikulkarni3986
    @shriharikulkarni3986 2 ปีที่แล้ว +1

    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?

  • @goktugerol1127
    @goktugerol1127 2 ปีที่แล้ว

    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.

  • @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.

  • @felixc.programs8209
    @felixc.programs8209 2 ปีที่แล้ว

    Good video as always! You motivated me to start my own Data Science/Engineering TH-cam channel myself. Can't wait for your future content!

  • @Paladin-ev1gg
    @Paladin-ev1gg 9 หลายเดือนก่อน

    Hello.
    What type of "seniority" are these qeustions?
    As someone who's looking for a first job in coding this seems difficult.

  • @nahfamimgood
    @nahfamimgood 2 ปีที่แล้ว +1

    so has FANG stopped doing leetcode algorithm style questions for FE positions?

    • @DrSatain
      @DrSatain 2 ปีที่แล้ว

      Looks like they've moved on to making people implement non-optimized browser functionality instead. Also silly, imo

  • @starlingroot
    @starlingroot 2 ปีที่แล้ว

    Quality content as always

  • @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

  • @Krilllind
    @Krilllind 2 ปีที่แล้ว +2

    For the `updateTimer` function I miss a discussion regarding time drift when using setTimeout. This HTTP 203 episode (th-cam.com/video/MCi6AZMkxcU/w-d-xo.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?

  • @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?

  • @azimb2280
    @azimb2280 2 ปีที่แล้ว

    Where we will get that job vacancy as react fe in google ? Ive never found job as fe in google

  • @giovannyalbarracin1141
    @giovannyalbarracin1141 ปีที่แล้ว

    Why didn't he use promise allsettled method in the first exercise?

  • @fiphee7776
    @fiphee7776 2 ปีที่แล้ว

    I'm new with JS but for the first problem shouldn't the slowPromise be at any position other than last position in the input promises array for it the be a useful test?

  • @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

  • @prathyushsunny
    @prathyushsunny 2 ปีที่แล้ว

    15:08 - that awkward moment everyone of us faced in online meetings

  • @yechielvizel
    @yechielvizel 2 ปีที่แล้ว

    I thought about the undefined edge case the second he said “will give you undefined”

  • @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

  • @sid4683
    @sid4683 2 ปีที่แล้ว

    The code editor is not visible clearly due to zoom out

  • @miguelpuentes9643
    @miguelpuentes9643 2 ปีที่แล้ว

    Next time can you make the font bigger , please

  • @capsenlu80
    @capsenlu80 2 ปีที่แล้ว

    I think the second one we can simplify to use JSON.stringify two objects and compare two string

    • @capsenlu80
      @capsenlu80 2 ปีที่แล้ว

      I take back my words as two objects might have different order of keys but might still equal.

  • @Sindoku
    @Sindoku 2 ปีที่แล้ว

    These are type of questions that Google will ask a FE dev? I could do this and I’m just a mid level developer. I thought that Google FED interviews would be harder?

  • @vulcs
    @vulcs 2 ปีที่แล้ว

    that is super easy - try instead to ask them to write a rollup plugin

  • @codewise8154
    @codewise8154 2 ปีที่แล้ว

    can this statement be valid to check if value is NaN? .... valueOne === NaN

  • @jodufan8754
    @jodufan8754 2 ปีที่แล้ว

    Could nt you just use JSON.stringify for the deep Equals or would that be cheating? Just a guess??

  • @faruqkhan5035
    @faruqkhan5035 2 ปีที่แล้ว

    As a Js - React developer is it required Hard DSA to get a job in google ?