Тёмный

1 Years Experienced Best Javascript Interview | Chakde Frontend Interview EP - 05 

Chirag Goel
Подписаться 24 тыс.
Просмотров 9 тыс.
50% 1

I've read all your comments, and I appreciate your feedback! Many of you have asked for content that helps freshers, so in this episode, I'm interviewing a candidate with one year of experience. I'm glad that you all are loving the content I'm bringing in. Last time, we had a candidate with 7.5 years of experience, and many of you enjoyed that episode. However, I want this series to also help freshers crack their next interview and grow in their careers. #chakdefrontendinterview
Share your answer on the comment box with the time stamp, share this on Linkedin with your solution and & tag me . Lets make this series best for cracking "frontend interviews".
Give your love and support to this episode .
Connect to learn & grow together in our career❤️:
✅ Linkedin: / engineerchirag
✅ Twitter: / engineerchirag
✅ Instagram: / engineerchirag
Music track: Wanderer by walen
Source: freetouse.com/music
No Copyright Background Music
#interview #react #javascript #chakdeinterviews #frontenddevelopment #mockinterview

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

 

30 май 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 104   
@trianglesundefined
@trianglesundefined 27 дней назад
Questions: 1. Chunk Approach 1: Using Slice Operation In this approach, we use the `slice` method to create subarrays. const chunk = (arr, size) => { let n = arr.length; const ans = []; for (let i = 0; i < n; i += size) { ans.push(arr.slice(i, i + size)); } return ans; } let arr = [1, 2, 3, 4, 5]; // Size = 1 let size = 1; let res = chunk(arr, size); console.log(res); // [[1], [2], [3], [4], [5]] // Size = 2 size = 2; res = chunk(arr, size); console.log(res); // [[1, 2], [3, 4], [5]] // Size = 3 size = 3; res = chunk(arr, size); console.log(res); // [[1, 2, 3], [4, 5]] Approach 2: Iterating Through the Array and Adding Chunks One by One In this approach, we iterate through the array and build chunks manually. const chunk = (arr, size) => { const ans = []; let chunk = []; for (let i = 0; i < arr.length; i++) { chunk.push(arr[i]); if (chunk.length === size || i === arr.length - 1) { ans.push([...chunk]); chunk.length = 0; } } return ans; } let arr = [1, 2, 3, 4, 5]; // Size = 1 let size = 1; let res = chunk(arr, size); console.log(res); // [[1], [2], [3], [4], [5]] // Size = 2 size = 2; res = chunk(arr, size); console.log(res); // [[1, 2], [3, 4], [5]] // Size = 3 size = 3; res = chunk(arr, size); console.log(res); // [[1, 2, 3], [4, 5]]
@BlackTrader7080
@BlackTrader7080 27 дней назад
First approach was simple and easy to understand
@ppl_calls_me_dsk
@ppl_calls_me_dsk 27 дней назад
1 approach is from chatgpt😂
@shubhanshusahuu
@shubhanshusahuu 9 дней назад
This approach is dependent on slice method, in C lang, it will push garbage value at the last chunk, So do this:::: const input =[1,2,3,4,7] const Chunk=(arr = input, size =1)=>{ let result =[] for(let i = 0 ; i < arr.length; i=i+size){ console.log(i,i+size,arr.length) if(i+size >= arr.length){ result.push(arr.slice(i,arr.length)) } else{ result.push(arr.slice(i,i+size)) } } return result } console.log(Chunk(input, 3))
@naveenbasyal001
@naveenbasyal001 4 дня назад
Using Splice which modifies the original arr and helps to easily cut out the portion and add it to and:- var chunk = function (arr, size) { const result = []; while (arr.length > 0) { const portion = arr.splice(0, size); result.push(portion); } return result; };
@SanjaySingh-xw3mi
@SanjaySingh-xw3mi 28 дней назад
1.In this way we can also do the 1st question. function chunk(arr,size){ let result=[]; let i=0; while(i
@mohammadsaqib7927
@mohammadsaqib7927 25 дней назад
What if arr[i] become 0 at any point then it will not work, 🤔
@sachintambeshwar9712
@sachintambeshwar9712 27 дней назад
Your videos are really brainstorming every time it is one level up , the way debounce can be asked and the scenarios that you asked helps a lot.
@engineerchirag
@engineerchirag 19 дней назад
❤️
@sandipamohanty2937
@sandipamohanty2937 22 дня назад
All the questions are amazing. Solved Chunk problem using splice. function chunk(arr, size) { if (size > arr.length) { return [arr]; } let count = Math.ceil(arr.length/size), result = [], startIndex = 0; for(let i = 0; i < count; i ++) { result.push(arr.splice(startIndex, size)); } return result; }
@nayansinghal5157
@nayansinghal5157 27 дней назад
CODE Question 1 :- The approach is to take only 1 variable and use it repeatedly. Time Complexity is O(N) as we need to traverse the whole array. function chunk(arr, size) { if(size >= arr.length) return arr; if(size
@prikshit8
@prikshit8 27 дней назад
Thank you Chirag for having me on your channel!
@rishabsharma5307
@rishabsharma5307 27 дней назад
bro from where did you practice JS interview based questions?
@prikshit8
@prikshit8 27 дней назад
@@rishabsharma5307 Leetcode JS GreatFrontend
@engineerchirag
@engineerchirag 27 дней назад
My pleasure ❤️
@mahakalstatus7856
@mahakalstatus7856 27 дней назад
Congrats sir🎉
@Piyush-xv1bb
@Piyush-xv1bb 28 дней назад
Every Video Of Chakde frontend Is A Gem for Us Thanks a lot Sir ❤❤❤❤
@engineerchirag
@engineerchirag 28 дней назад
❤️
@gunjanvyas695
@gunjanvyas695 28 дней назад
Awesome questions !! solution: /* chunk([1,2,3,4,5], 1) [[1],[2],[3],[4],[5]]; */ function chunk(arr, size) { let ans = []; let count = size; let temp = new Array(); for (let i = 0; i < arr.length; i++) { temp.push(arr[i]); count--; if (count { searchFn(...args); },delay); } } function print(data){ console.log(data); } let returnFun = debounce(print, 1000); returnFun("i"); returnFun("ip"); returnFun("iph"); returnFun("ipho"); /* q3 */ const count = (()=>{ let value = 0; function inner(){ value++; console.log(value); return value; } inner.reset = function(){ value=0; } return inner; })(); count();//1 count();//2 count();//3 count.reset()// count();//1 count();//2 count();//3
@user-xx9gc5xb1n
@user-xx9gc5xb1n 9 дней назад
function chunk(arr, size) { let result = []; for (let i = 0; i < arr.length; i = i + size) { result.push(arr.slice(i, i + size)); } return result; }
@mahekjariwala3560
@mahekjariwala3560 27 дней назад
For count function task may be we can assign reset and count as a property of countFn using dot operator. Example: function countFn() { countFn.count += 1; return countFn.count; } countFn.count = 0; countFn.reset = () => { countFn.count = 0; }
@naveenbasyal001
@naveenbasyal001 4 дня назад
➡️➡️Using Splice which modifies the original arr and helps to easily cut out the portion and add it to result- var chunk = function (arr, size) { const result = []; while (arr.length > 0) { const portion = arr.splice(0, size); result.push(portion); } return result; };
@sarthak290
@sarthak290 27 дней назад
So help me with something, once the miniAns is pushed in result array, why would the GC GC it?
@arbazh777
@arbazh777 28 дней назад
Thank you for the Chakde Frontend Interview series! It has been very helpful! 😊 Sir could you please clarify something from Task 1? How is this approach better: result.push([...minAns]); // Copying the content to a new array minAns.length = 0; compared to this approach: result.push(minAns); minAns = []; // Creates a new array for minAns Both seem to clear the array and both create a new array in memory, but in different ways. Could you explain why the first method is considered better than the second one?
@rohanp8354
@rohanp8354 22 дня назад
Basically you are creating many minAns[] arrays, which basically consuming more ram, If you use minAns.length = 0 You are using same array again and again without re-initializing it. That's y he got empty arrays in results When he made length = 0 Not copying content from new array its copying content from old array and emptying by assigning length 0
@imrankhan-km8wf
@imrankhan-km8wf 26 дней назад
For the first question. my solution is. const chunk = (arr, size) => { const result = []; for(let i=0; i< arr.length / size; i++){ const chunked = arr.slice(i * size, (i+ 1) * size) result.push(chunked); } console.log(result) }
@user-oi2tl9yt9c
@user-oi2tl9yt9c 28 дней назад
Sir you are a master piece ❤ I have a small request please bring a big project where you will do start things by explaining basics of any feature and we will end by creating that by our own . but please bring something.
@engineerchirag
@engineerchirag 28 дней назад
Good idea 😊
@sankhojjalchatterjee
@sankhojjalchatterjee 25 дней назад
Implemented chunk problem using slice: Here is the implementation. const chunk = (arr, size) => { const result = []; for (let i = 0; i < arr.length; ) { result.push(arr.slice(i, i + size)); i += size; } return result; };
@redsportsful
@redsportsful 6 дней назад
Thanks, I am learning lots of programing trick and solutions to your this series
@engineerchirag
@engineerchirag 2 часа назад
Great to hear!
@vedanshbisht1309
@vedanshbisht1309 28 дней назад
In the last question why the arrow function rather then normal function??
@skabadathaque8046
@skabadathaque8046 23 дня назад
function fun(arr, size){ const result = (curSize)=>{ if(curSize < arr.length){ console.log(arr.slice(curSize, curSize +size)) result(curSize+size) } } return result(0) }
@kumarvadivel4328
@kumarvadivel4328 28 дней назад
1. array chunking my solution: function chunk(arr,chunkSize){ let result = [] while(arr.length>chunkSize){ result.push(arr.splice(0,chunkSize)) arr.toSpliced(0,chunkSize) } result.push(arr) return result }
@gautamkhatri7895
@gautamkhatri7895 26 дней назад
question 1 ) best way of writing code function divide(chunk, size){ let res = []; while(chunk.length > size){ res.push(chunk.splice(0,size)); } if(chunk.length) res.push(chunk) return res }
@ScriptCodec
@ScriptCodec 26 дней назад
This is very helpful. I see this count(), count.reset() in libraries like jest. Thanks 🙏
@Harish-ms6zy
@Harish-ms6zy 21 день назад
Great video please do more such video for the beginners
@engineerchirag
@engineerchirag 21 день назад
More to come! ❤️
@anantsharma9806
@anantsharma9806 20 дней назад
These questions were quite a thinker!
@engineerchirag
@engineerchirag 20 дней назад
❤️
@strawhatrick
@strawhatrick 27 дней назад
Array length resetting to 0 makes the array empty was something new. Last i knew was that if we do function.length it gives us the number of arguments in the particular function
@strawhatrick
@strawhatrick 27 дней назад
The modified debounce question is really nice
@gautamkhatri7895
@gautamkhatri7895 26 дней назад
question 3) function createCount() { let counter = 0; const count = () => { counter++; return counter; }; count.reset = () => { counter = 0; }; return count; } // Usage: const count = createCount(); console.log(count()); // 1 console.log(count()); // 2 console.log(count()); // 3 count.reset(); // Reset the counter console.log(count()); // 1 console.log(count()); // 2 console.log(count()); // 3
@mayurwankhade7447
@mayurwankhade7447 25 дней назад
function chunk(arr, size) { let tempArr = []; for (let i = 0; i < arr.length; i = i + size) { tempArr.push(arr.slice(i, size + i)); } console.log(tempArr); } My solution to the first question
@krishparmar7917
@krishparmar7917 15 дней назад
Can anyone please tell me what code editor are they using ?
@karthiksundaram544
@karthiksundaram544 27 дней назад
@engineerchirag
@engineerchirag 19 дней назад
❤️❤️
@patelronak153
@patelronak153 20 дней назад
Valuable Content ❤
@engineerchirag
@engineerchirag 20 дней назад
❤️
@vivekmalviya3124
@vivekmalviya3124 27 дней назад
Tysm for this interview sir ❤❤
@engineerchirag
@engineerchirag 27 дней назад
My pleasure ❤️
@harshitagupta8641
@harshitagupta8641 28 дней назад
It's really amazing video 😍. I have learnt lot of things from this video.which will help me my upcoming interview.thanks alot chirag sir🙏 . keep posting these type of video. One thing I want to share, I know Prikshit Chawla ,he is my instructor of advance javascript.the way he is teaching is amazing. He is good instructor also❤🥰.
@engineerchirag
@engineerchirag 28 дней назад
Glad it was helpful! ❤️
@nimishgs3259
@nimishgs3259 25 дней назад
Counter problem: function countFunction() { this.value +=1 return this.value } const context = { value: 0, } const count = countFunction.bind(context); count.reset = function () { this.value = 0 }.bind(context) Chunking problem: const chunk = (arr, size) => { if(arr.length
@--VICKY-
@--VICKY- 25 дней назад
1. chunk const chunck = (arr,size) => { const chunkedArray = []; for(let i=0;i< arr.length;i+=size){ const subArr = arr.slice(i, i+size); chunkedArray.push(subArr) } return chunkedArray; }
@niteshrathore4341
@niteshrathore4341 26 дней назад
Question 1 Solution function chunk(array, size) { const result = []; for (let i = 0; i < array.length; i += size) { result.push(array.slice(i, i + size)); } return result; } console.log(chunk([1, 2, 3, 4, 5], 1)); console.log(chunk([1, 2, 3, 4, 5], 3));
@DebayanMukherjee-wo2ul
@DebayanMukherjee-wo2ul 23 дня назад
Lot's of high level concepts in your interviews......keep this but keep something for freshers also
@engineerchirag
@engineerchirag 19 дней назад
Many more episodes to come 🚀
@khanapeena2191
@khanapeena2191 27 дней назад
let countValue= 0; // define function let count = () => { countValue += 1; console.log("Count Value after increment: " + countValue); // Define and attach the reset function inside the count function count.reset = () => { countValue = 0; console.log("Count Value after reset: " + countValue); } } count(); count(); count(); count.reset(); that approch is simple and best i think
@wtfwithashutosh
@wtfwithashutosh 27 дней назад
( my Approach -> using pointer )function chunking(arr, chunk) { let result = []; let pointer = 0; for (let i = 0; i < arr.length; i++) { result[pointer] !== undefined ? result[pointer].push(arr[i]) : (result[pointer] = [arr[i]]); if (result[pointer].length === chunk) { pointer++; } } return result; } console.log(chunking([1, 2, 3, 4, 5], 1)); console.log(chunking([1, 2, 3, 4, 5], 2)); console.log(chunking([1, 2, 3, 4, 5], 3)); console.log(chunking([1, 2, 3, 4, 5], 4)); console.log(chunking([1, 2, 3, 4, 5], 5));
@amandubey4412
@amandubey4412 27 дней назад
Befor watching this video i didn't know how garbage collector work but after the first question i understand thanks chirag
@engineerchirag
@engineerchirag 27 дней назад
❤️
@JgNt3981
@JgNt3981 22 дня назад
@amandubey4412 Do you mind sharinng it here what u got to know about GC?
@saravind3153
@saravind3153 28 дней назад
For the first question i feel chirag tried to go for over optimisation , Actually whatever the approach prikshit has given is the optimal solution. Here are the reasons why ? 1. spread operator copies the data from one array to another array which takes O(k) TC. 2. Updating the length of the array `arr.length = 0` will internally removes all the elements ( which is again be given to the garbage collector ) and takes an additional O(k) TC though it seems to take constant TC. So the overall TC for chirag's solution would be O( n * k ) where `n` total length of source array and `k` is the chunk size & SC will be O(k) But for the first approach which prikshit has written takes O(n) TC and O(k) SC.
@prikshit8
@prikshit8 27 дней назад
I realised this after interview. Couldn't think of it during interview because of recording factor nervousness. 😅
@mrbytstudio
@mrbytstudio 27 дней назад
let counter = 0; function count(){ return counter += 1; } count.reset = function(){ counter = 0; } count(); // 1 count(); // 2 count.reset(); // 0 count(); // 1 count(); // 2 count(); // 3 console.log(counter); // 3 Thoughts please?
@gokul6120
@gokul6120 28 дней назад
is that it will work here 😅 sorry let i = 1; function count(){ console.log(i++); return { reset:function(){ i = 0; } } } count(); count(); count().reset(); count(); count(); count(); count();
@travelglobe8997
@travelglobe8997 27 дней назад
This should do it const chunk = (array, size) => { const chunkedArray = []; for (let i = 0; i < array.length; i += size) { chunkedArray.push(array.slice(i, i + size)); } return chunkedArray; };
@sarthak290
@sarthak290 27 дней назад
I believe he comes from a CP background, and doesn't know JS in depth
@prabhatkumar1162
@prabhatkumar1162 27 дней назад
Doing great chirag 💯 💯 🎉
@engineerchirag
@engineerchirag 19 дней назад
❤️
@sumitkumardey3268
@sumitkumardey3268 27 дней назад
@Chirag Its Beauty..
@engineerchirag
@engineerchirag 27 дней назад
❤️
@jayeshthanvi1115
@jayeshthanvi1115 27 дней назад
Q1 Please review function chunk(data, size) { const update = []; let row = []; for (let i = 0; i < data.length; i++) { row.push(data[i]); if (row.length === size || i === data.length - 1) { update.push(row); row = []; } } return update; }
@Shailesh8788
@Shailesh8788 27 дней назад
Is these correct way of doing ? function myCount() { let i = 0; function innerCount() { i++; console.log(i) } innerCount.reset = function() { i=0; } return innerCount; } const count = myCount();
@sohailahmad8844
@sohailahmad8844 26 дней назад
learned a lot from the problem you ask...Prikshit Selected
@engineerchirag
@engineerchirag 19 дней назад
❤️
@bhanuprakash1863
@bhanuprakash1863 28 дней назад
First comment, we want more videos like this .
@engineerchirag
@engineerchirag 28 дней назад
More to come! ❤️
27 дней назад
Wallmart my dream company
@aqibmalik6313
@aqibmalik6313 27 дней назад
could we use this ◦•●◉✿keyword in the last question✿◉●•◦
@rahulnikam1279
@rahulnikam1279 28 дней назад
More such interviews 😜
@engineerchirag
@engineerchirag 27 дней назад
Many more in pipeline 🚀
@rahulnikam1279
@rahulnikam1279 27 дней назад
@@engineerchirag amazing 🤞🏻❣️
@hkdelhivlogs
@hkdelhivlogs 25 дней назад
Hi Chirag could you please suggest from where we can find and prepare these type of questions. It will really helpful for us. Thanks in advance
@engineerchirag
@engineerchirag 19 дней назад
Chakde Frontend Interviews series 😛
@rishabsharma5307
@rishabsharma5307 28 дней назад
Solution for question 1 in typescript: ``` const chunk = (arr: T[], size: number) => { let itemsArr: T[] = []; return arr.reduce((acc, item, index) => { itemsArr.push(item); if (itemsArr.length === size) { acc.push([...itemsArr]); itemsArr.length = 0; } if (index === arr.length - 1 && itemsArr.length > 0) { acc.push(itemsArr); } return acc; }, []); }; console.log(chunk([1, 2, 3, 4, 5], 3)); ```
@rishabsharma5307
@rishabsharma5307 28 дней назад
Solution for question 2: ``` // debounce method const debounce = (cb: Function, delay: number) => { let timer: number | undefined; let isFirstCall = true; return (...args: any[]) => { clearTimeout(timer); timer = setTimeout(() => { cb(...args); }, delay); // set the timer to undefined so that the timer for the first call isn't cleared if (isFirstCall) { timer = undefined; } isFirstCall = false; }; }; ```
@ankittyagi6706
@ankittyagi6706 28 дней назад
let arr=[1,2,3,4,5], size=3 function chunk(arr:any[],size:number){ let ans=[]; let tempArr=[] for(let el of arr){ let k= tempArr.length;//0 if(k
@openworld7585
@openworld7585 28 дней назад
// please implement your chunk(arr:any[],size:number) function chunk(arry=[],size){ let anotherArray = [] while (arry.length>0) { let smallArray = arry.splice(0,size) anotherArray.push(smallArray) } return anotherArray } console.log(chunk([1,2,3,4,5],1)) console.log(chunk([1,2,3,4,5],2)) console.log(chunk([1,2,3,4,5],3)) console.log(chunk([1,2,3,4,5],4)) console.log(chunk([1,2,3,4,5],5)) this is my answer
@sukdipkar8876
@sukdipkar8876 22 дня назад
Brainstorming 🔥
@engineerchirag
@engineerchirag 20 дней назад
❤️
@openworld7585
@openworld7585 27 дней назад
let increCount =1 function count() { return increCount++ } count.reset = function (){ increCount = 1 } console.log(count()) console.log(count()) console.log(count()) count.reset() console.log(count()) console.log(count()) console.log(count())
@gokul6120
@gokul6120 28 дней назад
this is also working.... let i = 0; function foo(){ console.log(i++); } foo.reset = function (){ i = 0; } foo(); foo(); foo(); foo.reset(); foo(); foo(); foo(); foo();
@jebaparvin9835
@jebaparvin9835 27 дней назад
Prikshit sir 🫡
@engineerchirag
@engineerchirag 19 дней назад
❤️
@divyayogesh3936
@divyayogesh3936 22 дня назад
Accio faculty 😂
@rohitsharma7553
@rohitsharma7553 27 дней назад
function chunk(arr, size){ let res = [] let min = [] arr.forEach((item, idx)=>{ if(min.length < size){ min.push(item) }else{ res.push(min) min = [item] } }) res.push(min) return res } console.log(chunk([1,2,3,4,5], 4)) not solved coding problem from last 1 year and after solving this problem, before the candidate now i feel like i am still worthy. 😛 thanks for the video @engineerchirag const count = (() =>{ let c = 0 return function (){ c++ return c } })() count.reset = () =>{ c = 0 return 0 } console.log(count()) console.log(count()) console.log(count.reset())
@ishukhurana1779
@ishukhurana1779 26 дней назад
I have one doubt in debouncing problem if anyone can answer that. When declaring variable id or first inside debounce function, will it not create a new copy every time debounce is called. How can we remember the old ID or whether it is a first keystroke or not?? @engineerchirag
@prikshit8
@prikshit8 26 дней назад
Study closures. We are not invoking debounce function again and again. We are just invoking return function.
@jacquelynecarmen
@jacquelynecarmen 27 дней назад
function chunk(arr, size) { return Array.from({ length: Math.ceil(arr.length / size) }, (_, i) => arr.slice(i * size, i * size + size) ); }
Далее
Top 3 Languages for Web Development
0:57
Просмотров 843 тыс.
Stray Kids <ATE> UNVEIL : TRACK "MOUNTAINS"
00:59
Просмотров 949 тыс.
I loved solving this junior react interview challenge
26:02
2.5 Years Experienced Best JavaScript Interview
2:03:06
Просмотров 157 тыс.
Stray Kids <ATE> UNVEIL : TRACK "MOUNTAINS"
00:59
Просмотров 949 тыс.