Where do I code the runningTotal…? Right now I have it in handleCalc so I can keep it updated as inputs are added. But maybe it makes more sense to have it in handleResult when the user clicks the = button…?
I have collected all the inputs from calculator as an array called inputs. And now I want to reduce that array to a single value. Can I use reduce or should I make my life easier and use a for loop…?
Take my reply with a grain of salt as I am still learning React myself but it makes more sense in my mind to handle the total in handleResult and update after the user clicks the = button.
reduce is a great way to get a total from the array of inputs…it’s also cleaner with less chances to make syntax mistakes or mathmatical errors. My philosophy is ‘work smarter not harder’ and reduce does all the heavy lifting for you with less code so that would be my suggestion