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.
>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. -_-
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.
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 😅
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!
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!
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.
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 ;)
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!!
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
10 месяцев назад
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
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]);
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.
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)
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
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)
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
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