Google JavaScript Interview With A Frontend Engineer

Google JavaScript Interview With A Frontend Engineer

Clément Mihailescu

2 года назад

203,303 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Izaak Chater
Izaak Chater - 17.07.2023 07:41

Object.prototype.toString.call(obj) === "[object Object]" is what I use to determine if an element is an object... its on the cusp of being hacky but it does work

Ответить
2 Mindz
2 Mindz - 25.06.2023 08:33

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

Ответить
Giovanny Albarracin
Giovanny Albarracin - 02.05.2023 05:36

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

Ответить
Keiran Grant
Keiran Grant - 19.04.2023 10:00

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

Ответить
MapleJokerRofl
MapleJokerRofl - 08.04.2023 02:35

Would you like me to help
You get rid of your lisp ?

Ответить
Ellie P.
Ellie P. - 08.04.2023 01:49

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
}

Ответить
Tony Sebastian
Tony Sebastian - 02.02.2023 21:03

function deepEquals(x, y) {

// All primitives, all same object references.
if (x !== null && y != null && x === y) return true;

// Edge case for primitives : Null
if (x === null && y === null) return true;

// Edge case for primitives : NaN
let xIsNan = Number.isNaN(x);
let yIsNan = Number.isNaN(y);
if (xIsNan && yIsNan) return true;


// Edge case for objects : One is array, make sure the other is array as well.
if ((Array.isArray(x) && !Array.isArray(y))
|| (!Array.isArray(x) && Array.isArray(y))) {
return false;
}

// Edge case for objects: Date
if(x instanceof Date && y instanceof Date){
return x.getTime() === y.getTime();
}

// Objects
if (typeof x === 'object' && x !== null && typeof y === 'object' && y != null) {
const xKeys = Object.keys(x);
const yKeys = Object.keys(y);
if (xKeys.length == yKeys.length) {

for (key of xKeys) {
if (!deepEquals(x[key], y[key])) {
return false;
}
}
return true;
}
}
return false;
}

Ответить
Kuti
Kuti - 16.01.2023 23:00

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.

Ответить
Goktug Erol
Goktug Erol - 09.01.2023 23:49

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.

Ответить
Faruq Khan
Faruq Khan - 31.12.2022 09:54

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

Ответить
Inspireee
Inspireee - 19.12.2022 09:08

Great video, terrible language. Javascript is absolute asscheeks

Ответить
Lucas Silva
Lucas Silva - 16.12.2022 04:40

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.

Ответить
John Goodrow
John Goodrow - 07.11.2022 02:53

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

Ответить
BGivo
BGivo - 19.10.2022 21:57

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

Ответить
Azim B
Azim B - 13.10.2022 17:28

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

Ответить
Anshu Jindal
Anshu Jindal - 29.09.2022 20:55

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.

Ответить
Farhang Q
Farhang Q - 18.09.2022 18:20

oh god. weird js for ever😅

Ответить
Oliyide Ibrahim
Oliyide Ibrahim - 18.09.2022 12:01

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

Ответить
Howard zhang
Howard zhang - 03.09.2022 08:12

why not ”With A Frontend Expert“? maybe you think he is not so good?

Ответить
Usama Imran
Usama Imran - 21.08.2022 08:06

Why cant we convert non primitives to string and compare those strings

Ответить
Anirban Bhattacharya
Anirban Bhattacharya - 15.08.2022 12:48

Just a FYI. You dont have to use the name 'Google' for every mock interview just to attract viewers. Keep your content quality good and you will get viewers. You seem to be too much obsessed with Google, Facebook, Amazon.

Ответить
misterswaggie
misterswaggie - 14.08.2022 00:35

slow down when u talk

Ответить
Alejandro Baez Arcila
Alejandro Baez Arcila - 29.07.2022 18:57

very good content

Ответить
izyo
izyo - 21.07.2022 19:16

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

Ответить
Kirby Gordon
Kirby Gordon - 20.07.2022 04:12

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

Ответить
Capsen Lu
Capsen Lu - 16.07.2022 15:40

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

Ответить
The Hierophant
The Hierophant - 15.07.2022 21:03

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

Ответить
Andrew N
Andrew N - 11.07.2022 21:19

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

Ответить
corv882002
corv882002 - 11.07.2022 03:13

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.

Ответить
Giga Spy
Giga Spy - 10.07.2022 13:24

you could have used lodash's _.isEqual(val1, val2);

Ответить
Yuriy Batsura
Yuriy Batsura - 09.07.2022 16:37

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

Ответить
Pawel Kempinski
Pawel Kempinski - 09.07.2022 16:01

Front end and engineer... find the mistake

Ответить
Anup Mahato
Anup Mahato - 08.07.2022 12:12

Wonderful interview. @Corner Ardman I think one edge case is missed in PromiseAll problem , when you don't pass any promise to PromiseAll function.

Ответить
Carmelo Ramirez
Carmelo Ramirez - 08.07.2022 00:58

amazing your content.

Ответить
Ruy Vieira
Ruy Vieira - 07.07.2022 22:21

const deepEqual = (a,b) =>
(typeof a != typeof b || (a==null) !== (b==null)) ? ((a,b) => {
if(typeof a === "object" && a){
let keys = Object.keys(a)
if(keys.length != Object.keys(b).length) return (() => false)()
for(let i = 0; i < keys.length ; i++)
if(b[keys[i]] !== a[keys[i]]) return (() => false)()
return (() => true)()
} return (() => false)()
})() : ((a,b) => a === b)()

It will probably break if an object member is a reference to another object, but I don't care, close enough
edit: it's wrong but it's cute
edit2: now it works kind of
edit3: now it's more better and more improved
edit4: now it's more functional react js style with no impurities

Ответить
Ruy Vieira
Ruy Vieira - 07.07.2022 22:07

let a = { x : 33, y : 44}
let b = { y : 44, x : 33}

console.log(a === b)
console.log(JSON.stringify(a) === JSON.stringify(b))

b = { x : 33, y : 44}

console.log(a === b)
console.log(JSON.stringify(a) === JSON.stringify(b))

Ответить
Rad Houze
Rad Houze - 07.07.2022 06:57

Conner has an annoying voice, sorry but I gotta say it. Try to speak a bit deeper so you don't sound like a preteen. Other than that good stuff

Ответить
stanleyyyyyyyyyyy
stanleyyyyyyyyyyy - 07.07.2022 06:22

this just proves how huge mess the javascript is.

Ответить
Plus
Plus - 06.07.2022 21:17

I decided to try it too 😅


function deepEquals(valueOne, valueTwo) {
if (valueOne === valueTwo) {
return true;
}

const isObject = (obj) => obj !== null && typeof obj === 'object';
if (isObject(valueOne) && isObject(valueTwo)) {
const keys = [...Object.keys(valueOne), ...Object.keys(valueTwo)];

return keys.every((key: string) => deepEquals(valueOne[key], valueTwo[key]));
} else if (Array.isArray(valueOne) && Array.isArray(valueTwo)) {
if (valueOne.length !== valueTwo.length) {
return false;
}

return valueOne.every((value, index) => deepEquals(valueOne[index], valueTwo[index]));
} else if (typeof valueOne === 'function' && typeof valueTwo === 'function') {
return valueOne.toString() === valueTwo.toString();
}

return valueOne === valueTwo || Number.isNaN(valueOne) && Number.isNaN(valueTwo);
}

Ответить
The Chad
The Chad - 06.07.2022 01:02

deepEqual function, simply

function deepEqual(v1: any, v2: any): boolean {
if(typeof v1 === "object" && typeof v2 === "object")
return JSON.stringify(v1) === JSON.stringify(v2)
if(typeof v1 === 'function' && typeof v2 === 'function')
return v1.toString() === v2.toString()

return v1 === v2;
}

this is a fancy version of it

function deepEqual(v1: any, v2: any): boolean {

    return (
        typeof v1 === 'object' && typeof v1 === 'object'
     )
        ?
            JSON.stringify(v1) === JSON.stringify(v2)
        :
            (
                typeof v1 === 'function' && typeof v2 === 'function'
             )
                ?
                    v1.toString() === v2.toString()
                :
v1 === v2

}

Ответить
Gabriel Crowe
Gabriel Crowe - 05.07.2022 23:02

Serious question:

Why is this not appropriate for deepEquals?

const deepEquals = (object1, object2) => JSON.stringify(object1) == JSON.stringify(object2);

Ответить
amrut parab
amrut parab - 05.07.2022 20:13

One more condition is missing, if array is not sorted and have random similar numbers like v1= [2, 4, 6] v2= [4, 2, 6]. In that case this is going to fail.

Ответить
lifting is fun
lifting is fun - 05.07.2022 18:04

Man this guy is so weird hahaha hahaha hahaha lol

Ответить