1var obj = {a: 1, b: 2, undefined: 1};
2
3Object.keys(obj).reduce((a, b) => (obj[a] > obj[b]) ? a : b);
4
1let objects = [{id: 0, votes: 5}, {id: 1, votes: 3}, {id: 2, votes: 11}]
2
3let maxObj = objects.reduce((max, obj) => (max.votes > obj.votes) ? max : obj);
4
5/* `max` is always the object with the highest value so far.
6 * If `obj` has a higher value than `max`, then it becomes `max` on the next iteration.
7 * So here:
8 * | max = {id: 0, votes: 5}, obj = {id: 1, votes: 3}
9 * | max = {id: 0, votes: 5}, obj = {id: 2, votes: 11}
10 * reduced = {id: 2, votes: 11}
11 */