Q:

Find Variable with Max Value

After creating a quiz, I'd like to show the user what style of design they chose most commonly throughout (minimalist, modern, etc.) - I store the choice of each question, then at the end I'd like to show which was picked most commonly.
Essentially, if an option is picked (for example minimalist) I increment a separate value by 1 to reflect this. There are 9 options throughout the quiz, therefore I need to select which of these 9 options has the highest value stored against it.
What would be the most efficient way to do this?

A:

Efficiency is about how fast the code runs and scales, you are talking about "neatness of implementation" (well that's what I would call it!).
And for that, I would suggest you use 9 key,value pairs in an object to store these things rather than 9 variables.
This just makes more sense as they are related (I'm sure someone can come up with annoying coding paradigm that encompasses this, but it just makes sense to me!).
An advantage of arranging what is essentially your "data structure" in this way is that the code becomes super neat.
Check it out:
my_counts = {'a': 10, 'b': 1, 'c': 5} // and so on...
max_count = Math.max(...Object.values(my_counts))

Which gives max_count as 10.

