I've got a simple piece of code that finds the highest number in an array.
const getMax = (data) => Object.entries(data).reduce((max, item) => max[1] > item[1] ? max : item);
var myData1 = { a: 1, b:2, c: 3};
var myData2 = { a: 4, b:2, c: 3};
console.log(getMax(myData1));
console.log(getMax(myData2));
The result returned:
[ 'c', 3 ]
[ 'a', 4 ]
This function is crucial for various tasks. How can I specifically print only the first calculated value ('c' or 'a') and then specifically print the output of the second value (3 or 4)?
Appreciate any help on this. Thanks.