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

Поділитися
Вставка
  • Опубліковано 4 лют 2025

КОМЕНТАРІ • 128

  • @sachintambeshwar9712
    @sachintambeshwar9712 8 місяців тому +2

    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.

  • @theramgoel
    @theramgoel 13 днів тому

    For first one:
    function chunkArray(arr, chunkSize) {
    let map = {};
    let i = 0;
    if (chunkSize < 0) throw new Error("Chunk side should be greater than 0");
    if (chunkSize >= arr.length) return [arr];
    while (i < arr.length) {
    let currentChunk = arr.slice(i, Math.min(i + chunkSize, arr.length));
    map[i.toString()] = currentChunk;
    i += chunkSize;
    }
    return Object.values(map);
    }

  • @nabaraj123
    @nabaraj123 4 місяці тому

    The interview was very informative. The candidate's technical skills and grasp of JavaScript concepts were particularly impressive.

  • @sandipamohanty2937
    @sandipamohanty2937 8 місяців тому +1

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

    • @_aamir
      @_aamir 6 місяців тому

      This is how I solved it using do while loop and splice method -
      function chunk(arr, size) {
      let givenArr = [...arr];
      let result = [];
      do {
      result.push(givenArr.splice(0, size));
      } while (givenArr.length > 0);
      return result;
      }

  • @sravan8643
    @sravan8643 18 днів тому

    The last question was really interesting. Learnt many new things!

  • @vishalgangde702
    @vishalgangde702 7 місяців тому

    Incredibly informative and engaging Interview Series! You’ve made a complex interview topic so easy to understand with clear explanation. This is exactly the kind of interview content we need more of. Great job Sir! 🧠💡

  • @Piyush-xv1bb
    @Piyush-xv1bb 8 місяців тому +1

    Every Video Of Chakde frontend Is A Gem for Us
    Thanks a lot Sir ❤❤❤❤

  • @AmandeepSingh-sx9ke
    @AmandeepSingh-sx9ke 4 місяці тому

    Please keep posting more videos. It really helps. Thank a lot

  • @shubhamsharma2773
    @shubhamsharma2773 4 місяці тому

    I think for the first problem(chunk), the correct comparison would be that the milkman is washing the jar with water every time he pours the milk instead of using a new one. And the correct approach would be just to use the same jar without even washing it.
    Tha last question was amazing🎉

  • @AmandeepSingh-sx9ke
    @AmandeepSingh-sx9ke 4 місяці тому

    Nice video. Please keep posting such interview videos

  • @harshitagupta8641
    @harshitagupta8641 8 місяців тому

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

  • @imrankhan-km8wf
    @imrankhan-km8wf 8 місяців тому

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

  • @TheMonkTalks-w6n
    @TheMonkTalks-w6n 8 місяців тому

    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.

  • @AmandeepSingh-sx9ke
    @AmandeepSingh-sx9ke 4 місяці тому

    Quality questions

  • @大盗江南
    @大盗江南 7 місяців тому

    this is such a great mock interview, learnt a lot from u, will buy ur courses! First time I want to buy these online courses! Thank you! Plz make more!

    • @engineerchirag
      @engineerchirag  7 місяців тому

      Awesome, thank you! ❤️❤️ That means a lot to me 🙏

  • @redsportsful
    @redsportsful 7 місяців тому

    Thanks, I am learning lots of programing trick and solutions to your this series

  • @sankhojjalchatterjee
    @sankhojjalchatterjee 8 місяців тому +1

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

  • @SanjaySingh-xw3mi
    @SanjaySingh-xw3mi 8 місяців тому +3

    1.In this way we can also do the 1st question.
    function chunk(arr,size){
    let result=[];
    let i=0;
    while(i

    • @mohammadsaqib7927
      @mohammadsaqib7927 8 місяців тому

      What if arr[i] become 0 at any point then it will not work, 🤔

  • @anantsharma13
    @anantsharma13 8 місяців тому

    These questions were quite a thinker!

  • @arbazh777
    @arbazh777 8 місяців тому +2

    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 8 місяців тому

      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

  • @hetpatel1772
    @hetpatel1772 5 місяців тому

    the first question led to debate in chat for time and space complexity
    i have done small research why the approach shown by chirag bhai is good.
    if we are not altering the value of miniAss for the approach of prikshit then that approach is very good,
    but if we are altering the value which in production we never knows the things go hand in hand - so for that reason the approach of chirag bhai is fine enough.

  • @strawhatrick
    @strawhatrick 8 місяців тому

    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 8 місяців тому

      The modified debounce question is really nice

  • @saravind3153
    @saravind3153 8 місяців тому +4

    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 8 місяців тому +2

      I realised this after interview. Couldn't think of it during interview because of recording factor nervousness. 😅

  • @prikshit8
    @prikshit8 8 місяців тому +4

    Thank you Chirag for having me on your channel!

    • @rishabsharma5307
      @rishabsharma5307 8 місяців тому

      bro from where did you practice JS interview based questions?

    • @prikshit8
      @prikshit8 8 місяців тому

      @@rishabsharma5307
      Leetcode JS
      GreatFrontend

    • @engineerchirag
      @engineerchirag  8 місяців тому

      My pleasure ❤️

    • @mahakalstatus7856
      @mahakalstatus7856 8 місяців тому

      Congrats sir🎉

  • @GreenLadderNow
    @GreenLadderNow 8 місяців тому

    Befor watching this video i didn't know how garbage collector work but after the first question i understand thanks chirag

    • @engineerchirag
      @engineerchirag  8 місяців тому

      ❤️

    • @JgNt3981
      @JgNt3981 8 місяців тому

      @amandubey4412 Do you mind sharinng it here what u got to know about GC?

  • @DebayanMukherjee-wo2ul
    @DebayanMukherjee-wo2ul 8 місяців тому

    Lot's of high level concepts in your interviews......keep this but keep something for freshers also

  • @Harish-ms6zy
    @Harish-ms6zy 8 місяців тому

    Great video please do more such video for the beginners

  • @nayansinghal23
    @nayansinghal23 8 місяців тому +1

    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

  • @trianglesundefined
    @trianglesundefined 8 місяців тому +8

    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 8 місяців тому

      First approach was simple and easy to understand

    • @ppl_calls_me_dsk
      @ppl_calls_me_dsk 8 місяців тому

      1 approach is from chatgpt😂

    • @shubhanshusahuu
      @shubhanshusahuu 7 місяців тому

      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 7 місяців тому

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

  • @kumarvadivel4328
    @kumarvadivel4328 8 місяців тому

    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
    }

  • @patelronak153
    @patelronak153 8 місяців тому

    Valuable Content ❤

  • @thangellapelliarchana4169
    @thangellapelliarchana4169 5 місяців тому +1

    Question 2
    //without abort controller
    function debouncing(fnc, delay) {
    let timer;
    let firstTime = true;
    let latestRequestId = 0;
    return function (...args) {
    latestRequestId++; // Increment the counter for each call
    const currentRequestId = latestRequestId; // Store the current request id
    if (firstTime) {
    fnc(...args).then((response) => {
    // Only process the response if it belongs to the latest request
    if (currentRequestId === latestRequestId) {
    console.log(response);
    }
    });
    firstTime = false;
    } else {
    if (timer) {
    // fnc(...args);
    clearTimeout(timer);
    }
    timer = setTimeout(() => {
    fnc(...args).then((response) => {
    // Only process the response if it belongs to the latest request
    if (currentRequestId === latestRequestId) {
    console.log(response);
    }
    });
    }, delay);
    }
    };
    }
    function print(data) {
    return new Promise((resolve) => {
    // Simulate variable delay in API response
    const randomDelay = Math.floor(Math.random() * 10) + 1; // Random delay between 1ms to 10ms
    setTimeout(() => {
    resolve(`API Response for: ${data} (after ${randomDelay}ms)`);
    }, randomDelay);
    });
    }
    let searchTerm = debouncing(print, 1000);
    //case 1: for the first time the default data should show
    searchTerm("I");
    searchTerm("Ip");
    searchTerm("Iph");
    searchTerm("Ipho");
    //with AbortController
    function debouncing(fnc, delay) {
    let timer;
    let firstTime = true;
    let controller = new AbortController();
    return function (...args) {
    if (firstTime) {
    controller = new AbortController();
    fnc(...args, controller.signal).then((response) => {
    console.log(response);
    });
    firstTime = false;
    } else {
    if (timer) {
    // fnc(...args);
    clearTimeout(timer);
    }
    timer = setTimeout(() => {
    controller.abort();
    controller = new AbortController(); // Create a new controller for the new request
    fnc(...args, controller.signal).then((response) => {
    console.log(response);
    });
    }, delay);
    }
    };
    }
    function print(data, signal) {
    return new Promise((resolve) => {
    // Simulate variable delay in API response
    const randomDelay = Math.floor(Math.random() * 10) + 1; // Random delay between 1ms to 10ms
    setTimeout(() => {
    if (signal.aborted) {
    reject(new DOMException("Aborted", "AbortError"));
    } else {
    resolve(`API Response for: ${data} (after ${randomDelay}ms)`);
    }
    }, randomDelay);
    });
    }
    let searchTerm = debouncing(print, 1000);
    //case 1: for the first time the default data should show
    searchTerm("I");
    searchTerm("Ip");
    searchTerm("Iph");
    searchTerm("Ipho");

  • @RajeshSinghaMahapatra-f2y
    @RajeshSinghaMahapatra-f2y 3 місяці тому

    function chunk(arr,size){
    let result = []
    let temp = []
    let count =0
    for(let i =0; i0){
    result.push(temp)
    }
    return result
    }

  • @niteshrathore4341
    @niteshrathore4341 8 місяців тому

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

  • @RamManoharKoruprolu
    @RamManoharKoruprolu 7 місяців тому

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

  • @sarthak290
    @sarthak290 8 місяців тому +1

    So help me with something, once the miniAns is pushed in result array, why would the GC GC it?

  • @vivekmalviya3124
    @vivekmalviya3124 8 місяців тому

    Tysm for this interview sir ❤❤

  • @bhanuprakash1863
    @bhanuprakash1863 8 місяців тому +7

    First comment, we want more videos like this .

  • @Nitya_Cute_Pari
    @Nitya_Cute_Pari 8 місяців тому

    Doing great chirag 💯 💯 🎉

  • @naveenbasyal001
    @naveenbasyal001 7 місяців тому

    ➡️➡️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;
    };

  • @khanapeena2191
    @khanapeena2191 8 місяців тому

    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

  • @gokul6120
    @gokul6120 8 місяців тому +1

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

  • @gautamkhatri7895
    @gautamkhatri7895 8 місяців тому +3

    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
    }

  • @gautamkhatri7895
    @gautamkhatri7895 8 місяців тому

    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

  • @krishparmar7917
    @krishparmar7917 7 місяців тому

    Can anyone please tell me what code editor are they using ?

  • @nimishgs3259
    @nimishgs3259 8 місяців тому

    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

  • @travelglobe8997
    @travelglobe8997 8 місяців тому

    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 8 місяців тому +1

      I believe he comes from a CP background, and doesn't know JS in depth

  • @vedanshbisht1309
    @vedanshbisht1309 8 місяців тому

    In the last question why the arrow function rather then normal function??

  • @ScriptCodec
    @ScriptCodec 8 місяців тому

    This is very helpful.
    I see this count(), count.reset() in libraries like jest.
    Thanks 🙏

  • @skabadathaque8046
    @skabadathaque8046 8 місяців тому

    function fun(arr, size){
    const result = (curSize)=>{
    if(curSize < arr.length){
    console.log(arr.slice(curSize, curSize +size))
    result(curSize+size)
    }
    }
    return result(0)
    }

  • @codecode-10
    @codecode-10 8 місяців тому

    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?

  • @Coder900
    @Coder900 4 місяці тому

    I dont know for 1st question why he didn't used the array method of slice. Here's an example for the same
    var calculated = []
    function chuncking(arr,length) {
    let newArr = [...arr]
    if(!newArr.length){
    return calculated
    } else {
    console.log(newArr)
    let SubArr = newArr.slice(0,length)
    calculated.push(SubArr)
    chuncking(newArr.slice(length), length)
    }
    }
    chuncking([1,2,3,4,5,6,7,8,9],2)
    console.log(calculated)
    Although I don't expect an 1 year experienced to give this answer but comment section is also using for loop for this. If javascript gave an method for this task why use an for loop for this.

  • @hkdelhivlogs
    @hkdelhivlogs 8 місяців тому

    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  8 місяців тому

      Chakde Frontend Interviews series 😛

  • @Shailesh8788
    @Shailesh8788 8 місяців тому

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

  • @wtfwithashutosh
    @wtfwithashutosh 8 місяців тому

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

  • @sumitkumardey3268
    @sumitkumardey3268 8 місяців тому

    @Chirag Its Beauty..

  • @janakiraokona9338
    @janakiraokona9338 7 місяців тому

    Chirag please suggest me best js dsa paid or free any?

  • @mayurwankhade7447
    @mayurwankhade7447 8 місяців тому

    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

  • @jacquelynecarmen
    @jacquelynecarmen 8 місяців тому

    function chunk(arr, size) {
    return Array.from({ length: Math.ceil(arr.length / size) }, (_, i) =>
    arr.slice(i * size, i * size + size)
    );
    }

  •  8 місяців тому +1

    Wallmart my dream company

    • @sumitbhardwaz
      @sumitbhardwaz 7 місяців тому

      Achaaaa. you will make it bro😄

  • @rahulnikam1279
    @rahulnikam1279 8 місяців тому

    More such interviews 😜

  • @mahekjariwala3560
    @mahekjariwala3560 8 місяців тому +1

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

  • @aqibmalik6313
    @aqibmalik6313 8 місяців тому

    could we use this ◦•●◉✿keyword in the last question✿◉●•◦

  • @sohailahmad8844
    @sohailahmad8844 8 місяців тому

    learned a lot from the problem you ask...Prikshit Selected

  • @igurutechs2583
    @igurutechs2583 5 місяців тому

    For 1st question I've followed this approach:
    const arr = [1,2,3,4,5];
    function chunk(arr, size) {
    let newArr = [];
    return arr.reduce((ac,cur,i) => {
    newArr = [...newArr,cur];
    if(newArr.length === size || i===arr.length-1) {
    ac = [...ac, newArr.splice(0, newArr.length)]
    }
    return ac;
    },[])
    }
    console.log(chunk(arr, 1))
    console.log(chunk(arr, 2))
    console.log(chunk(arr, 3))
    console.log(chunk(arr, 4))
    console.log(chunk(arr, 5))

  • @sukdipkar8876
    @sukdipkar8876 8 місяців тому

    Brainstorming 🔥

  • @ishukhurana1779
    @ishukhurana1779 8 місяців тому

    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 8 місяців тому

      Study closures. We are not invoking debounce function again and again. We are just invoking return function.

  • @karthiksundaram544
    @karthiksundaram544 8 місяців тому

  • @jayeshthanvi1115
    @jayeshthanvi1115 8 місяців тому

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

  • @--VICKY-
    @--VICKY- 8 місяців тому

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

  • @rishabsharma5307
    @rishabsharma5307 8 місяців тому

    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 8 місяців тому

      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;
      };
      };
      ```

  • @jebaparvin9835
    @jebaparvin9835 8 місяців тому +1

    Prikshit sir 🫡

  • @ankittyagi6706
    @ankittyagi6706 8 місяців тому

    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 8 місяців тому

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

  • @gokul6120
    @gokul6120 8 місяців тому

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

  • @mirage4731
    @mirage4731 6 місяців тому

    Count Question
    function count() {
    if (!count.prototype.cnt || count.prototype.cnt === 0) {
    count.prototype.cnt = 0;
    }
    count.prototype.cnt = count.prototype.cnt + 1;
    count.reset = () => {
    count.prototype.cnt = 0;
    return;
    };
    return count.prototype.cnt;
    }

  • @openworld7585
    @openworld7585 8 місяців тому

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

  • @Foodish_fun
    @Foodish_fun 4 місяці тому

    function deBounce(typing, delay, ...args) {
    setTimeout(() => {
    console.log(`Executing typing with args: ${args}`);
    typing(...args);
    }, delay);
    }
    function typing(a) {
    console.log(a);
    }
    // Calls that will now not overwrite each other
    deBounce(typing, 2000, "y");
    deBounce(typing, 3000, "ya");
    deBounce(typing, 100, "yas");
    deBounce(typing, 0, "yash");

  • @divyayogesh3936
    @divyayogesh3936 8 місяців тому

    Accio faculty 😂

  • @gunjanvyas695
    @gunjanvyas695 8 місяців тому +1

    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

  • @rohitsharma7553
    @rohitsharma7553 8 місяців тому

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

  • @RajeshSinghaMahapatra-f2y
    @RajeshSinghaMahapatra-f2y 3 місяці тому

    Bowl le, dudh nikal and usi bowl ko jake rakh ke ayy. Dubara ek neya bowl le.
    function chunk(arr,size){
    let result = [[]]
    for(let i =0; i