This react interview challenge was awesome to solve

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

КОМЕНТАРІ • 87

  • @alexliebhaber3109
    @alexliebhaber3109 Рік тому +44

    I’ve been watching you for a month now, and I just wanted to say thank you for doing what you do. It helps a lot how you explain what you’re thinking while you’re problem solving.

  • @TedMosby-fk5gj
    @TedMosby-fk5gj Рік тому +1

    Thank you for actually explaining the final product or what we need to do in the begenning. Some of your other code challenge videos I dont understand the problem or final result and end up not doing it. Great video.

    • @WebDevCody
      @WebDevCody  Рік тому

      I’ll try to remember to do that in future videos, thanks for the feedbacl

  • @DrifterXx22
    @DrifterXx22 Рік тому +8

    The fact that you can bring a real world problem into code is quite amazing. This skill is what every programmer should have.

    • @aeoliun
      @aeoliun Рік тому +2

      >The fact that you can bring a real world problem into code is quite amazing. This skill is what every programmer should have.
      I mean that's literally the definition of a software engineer's job. -_-

    • @TU7OV
      @TU7OV Рік тому

      @@aeoliun lmao

    • @rowsncols
      @rowsncols Рік тому +1

      @@aeoliun why did you quote him tho? the comment is above you

  • @germain1984
    @germain1984 Рік тому +1

    please never stop making videos, they're all super insightful

  • @FuzzyAnkles
    @FuzzyAnkles Рік тому +1

    really great content Cody. keep on rockin! It really helps understand react just by doign this small challenges.

  • @Kxneki2433
    @Kxneki2433 Рік тому +2

    I just wanted say thanks for this content, it would be really great if you keep on posting this challenges

  • @insensibility
    @insensibility Рік тому +8

    I love the way you teach. I am an aspiring Front-End Developer and currently a first year Information Technology student. If it ever cross your mind to recreate you beginner to full-stack developer series that would be great!
    Keep up!

  • @lougieq1291
    @lougieq1291 11 місяців тому +1

    The input error can be solved by parsing the value to int on your set state function like so: setItemsInPersonCart(parseInt(e.currentTarget.value));
    It gave such error since by default the input value is string.

  • @Bukosaure
    @Bukosaure Рік тому +1

    Love the way to verbalize your thought process and your humility. Keep it up Cody!

  • @andrewwall2730
    @andrewwall2730 Рік тому +2

    Great video and a fun challenge. Unless I missed something the only thing I would add is to clear the interval when all the lines are empty. Look forward to your next challenge. Also, can't you just put min="1' attribute on the input. Thank you for these challenges!

  • @ToddDunning
    @ToddDunning Рік тому +1

    Fantastic work Cody, man that last part was gnarly, I would have mentally checked out.

  • @gyros9162
    @gyros9162 Рік тому

    Thank you for this challenge! Taking this stuff with tills into React is great practice

  • @stevencoy
    @stevencoy Рік тому +1

    For someone learning React, this is extremely helpful.

  • @ardianhotii
    @ardianhotii Рік тому

    I really like your videos, especially these challenges. Keep doing these videos more, it helps me and people so much

  • @mavsocc
    @mavsocc 9 місяців тому

    the best learning is by debuggin. the videos with live debagging are the most heplful ones. thanks very much.

  • @diemantrabeats7551
    @diemantrabeats7551 Рік тому +22

    You have to set the input state to an empty string whenever you don’t want any value in it… also setting the input type to number doesn’t always prevent input of characters, they can type really fast and it can bug out, it’s better to do a second check and then convert the e.target.value to a number. There’s a Math.sign() that takes a string or a number and will return 1 for positive numbers, -1 for negative numbers, 0 for 0, -0 for -0, NaN for “foo”, 1 for “5”, and -1 for “-4”.
    Then you can do your if statements and set your state 😅

    • @WebDevCody
      @WebDevCody  Рік тому +10

      thanks for the info. My brain often goes blank when I do these live coding things

    • @Endrit719
      @Endrit719 Рік тому +2

      @@WebDevCody I feel you, I am pro when I do it alone, I am pepega when someone is watching me

  • @eshw23
    @eshw23 Рік тому

    These are great to do, I was able to do all of it except for the decrementing part, always good to fail and get a stronger grasp on these concepts

  • @thomasgold2022
    @thomasgold2022 Рік тому

    love your content. I really enjoy the verbal thought process

  • @annusingh4694
    @annusingh4694 Рік тому

    Great content as always! Thank you so much

  • @christopherjschultz
    @christopherjschultz Рік тому

    This is an awesome exercise! Thanks for sharing your solution, keep up the great work!

  • @Pvillanueva13
    @Pvillanueva13 Рік тому

    Appreciate the live problem solving sessions!

  • @haipengwu2649
    @haipengwu2649 Рік тому +2

    I think there might be a bug in this code. When adding to the new line, when there are more than one line that has the same amount of items in it on, it seems like the logic of line === lineWithLeast? [...line, itemsInPersonCart]:line will end up updating all of them, please let me know if that is the case? thank you

    •  Рік тому

      I check this. There is no bug. Works fine.
      example.
      const ar=[1];
      const arr=[1];
      console.log(ar === arr);
      // Expected output: false
      console.log(ar === ar);
      // Expected output: true

  • @RicardoGerbaudo
    @RicardoGerbaudo Рік тому +1

    great video! which vscode theme are you using?

  • @exoderp3651
    @exoderp3651 Рік тому

    Your videos are great for learning!! Problem solving is an essential skill and I love how you present these videos and explain your process. I learn a bunch of best practices and how I should break down problems in general. One thing is maybe include more descriptive titles and/or thumbnails? I would find it easier to find a problem I'd like to solve based off of descriptive titles or images instead of the generic ones. Just a suggestion. Keep up the great work!!

    • @exoderp3651
      @exoderp3651 Рік тому

      To clarify, this only really applies to the interview challenges.

    • @WebDevCody
      @WebDevCody  Рік тому

      Yeah maybe a screenshot of what we will build

  • @slemchik03
    @slemchik03 Рік тому

    Very good problem and his solution, thank you so much for your content!

  • @RavindraSingh-lp9pl
    @RavindraSingh-lp9pl Рік тому

    love from India ❤very useful videos...keep on postingsuch React Coding challenges

  • @kushalkamra3803
    @kushalkamra3803 Рік тому

    Thank you 🙏

  • @Mario-vq9ev
    @Mario-vq9ev Рік тому +1

    More videos like this!! Love it 🎉😂❤

  • @apaksimen
    @apaksimen Рік тому

    how do you rename on 9:57, what shortcut you've used?

  • @TheDenga147
    @TheDenga147 Рік тому

    I love yout videos!
    Quick question, what shortcut did you use at 9:52 to change all the variable names instead of the word itself??

  • @FiorinaEU
    @FiorinaEU Рік тому +1

    There's really no need for a foreach-loop when you could just use the traditional for-loop. This would give you the index directly of the line containing the least amount.
    Set lines[idx] = [...lines[idx], itemsInPersonCart] and then use this in the setState through setLines([...lines]). Simpler, faster and way easier to read.
    Otherwise, good challenge. I liked it and I raced you ;)

  •  Рік тому +1

    I would rate this solution 6/10

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

    You dont need to control the input because its value is only needed when you submit the form

  • @anthonygg_
    @anthonygg_ Рік тому

    Love this!

  • @reydez84
    @reydez84 Рік тому

    damn this is great practice, i watched it without code following but ima watch it again and gonna bust out my visual studio code

  • @iamvitalya
    @iamvitalya Рік тому

    could you tell, please, what VS Code color theme is it?

  • @sean_haz
    @sean_haz Рік тому

    What is your keyboard setup?
    Seems likeyou transition from keyboard to mouse instantly, what are you using for cursor control?

  • @josephito27
    @josephito27 2 місяці тому

    damn, my solutions is messy af, but it works well for the tasks asked (probably has some edge cases bugs, idk), I went with a single state, and an Array of Objects for the queues with a "clients" property.

  • @jorgejorge08
    @jorgejorge08 Рік тому

    Love it!!keep it up!

  • @notfadeaway6617
    @notfadeaway6617 Рік тому

    nice video. didn't understand why you have to setItemsinPersonCart(undefined) when "", could't you just pass it?

  • @ZantierTasa
    @ZantierTasa Рік тому +1

    react just doesn't seem to like value={undefined}
    Keeping the rest of your code the same, this fixes the error:
    value={itemsInPersonCart === undefined ? "" : itemsInPersonCart}
    (or you can use useState, rather than using undefined)

  • @bobbyboxer2664
    @bobbyboxer2664 Рік тому

    Does anyone know what theme he’s using?

  • @matttaydavis
    @matttaydavis Рік тому

    I like tackling these then comparing your methods vs mine to see where I can improve. It would be cool if you also gave an idea of how long you think it would take a beginner to tackle the problem, so I know just how inefficient my times are.

  • @frankkim9178
    @frankkim9178 Рік тому

    What’s the name of the extension that gives you the error messages next to your code?

  • @raymondmichael4987
    @raymondmichael4987 Рік тому

    Thanks, learned a thing or two

  • @ricko13
    @ricko13 Рік тому

    hey Cody why you using *e.currentTarget* instead of *e.target* ?

    • @WebDevCody
      @WebDevCody  Рік тому +2

      currentTarget is the actual dom element that the event listener is attached to. target is the thing that triggered the click event (which might not be the actual button clicked but instead maybe an icon inside the button)

  • @TheSourLemonz
    @TheSourLemonz Рік тому

    ur awesome to solve

  • @ghury1
    @ghury1 Рік тому

    hi, which vs code are you using?

  • @aleksandermarek5589
    @aleksandermarek5589 Місяць тому

    I don't really see the point to use onChange to the input in that case, because you always have to hit "checkout" so you cam get it from form data once you set name of that input. Then you can easily check inside of submit function whenever it doesnt match your requirements (less than 0 in that case).
    It is a good job but i see so many times people are using useState like that and I think it is not proper way to do that mainly because you are unnecessary rerendering stuff because of that. :)

  • @kklowd
    @kklowd Рік тому

    I didn't really understand the timing process. I would have created an interval for each line since that's how a line would process practically. this was a cool problem though

    • @WebDevCody
      @WebDevCody  Рік тому +2

      yeah that would be interesting as well, each queue has their own interval because some cashiers are faster than others.

    • @dr_davinci
      @dr_davinci Рік тому

      @@WebDevCody that sounds pretty interesting, I might give it a try :)

  • @butwhothehellknows
    @butwhothehellknows Рік тому

    Good job babe!!!

  • @Zechey
    @Zechey Рік тому

    Been working on this today, it seemed simple at first but setIntervals turned out to be pretty tricky to work with in React!

  • @yevhentarik4551
    @yevhentarik4551 Рік тому

    I don’t get in what real life problem I can use this approach… I mean it would be nice to have examples that actually deals with real dev problems not some general examples) cause as I understand your timer represents cashier work in this example

    • @WebDevCody
      @WebDevCody  Рік тому

      The point is to stress your problem solving abilities

  • @thesnarbo2814
    @thesnarbo2814 Рік тому

    why not just set min="1" on the input so you wont get negative or an undefined number? no need for JS here

  • @chrisstucker1813
    @chrisstucker1813 Рік тому

    My solution to this was awful lmao

  • @GitIsBeautiful
    @GitIsBeautiful Рік тому

    It is 😄 set the state to 0.

  • @lougieq1291
    @lougieq1291 11 місяців тому

    For the addPersonToLine function, I think instead of using map with the setLines method you can probably just use the spread operator like
    lines[lineWithLeast].push(itemsInPersonCart);
    setLines([...lines]);

  • @samjohnston3416
    @samjohnston3416 Рік тому +1

    Some more challenging ideas:
    - Each queue has its own interval using something like Math.random
    - Add or remove checkouts using buttons
    - Dynamically add or remove checkouts based if the line has more than 3 people waiting or total number of items exceeds 20 (in real world you would also have a limited number of checkouts and or staff)
    - Store checkouts stored in a key value pair object such as Maps

  • @casull6447
    @casull6447 Рік тому

    I just disabled the button like this ->