Let me know how to get the highest values for my variable Result
in this event for example :
if MyFruits ={ "Orange": 1, "Banana": 3, "Apple": 3 }
I would like to get "Banana"
and "Apple"
but It gives me only the first fruit : "Banana"
// first the variable MyFruits must have index 0
// and after the user clicks to give value.
var MyFruits = {
"Orange": 0,
"Banana": 0,
"Apple": 0
};
$('input:checked').each(function(index) {
var key = $(this).val();
if (key in MyFruits) {
MyFruits[key]++;
} else {
MyFruits[key] = 1;
}
});
var Result = Object.keys(MyFruits).reduce(function(a, b) {
return MyFruits[a] > MyFruits[b] ? a : b
});