I have an array of pokemon objects which have a Max and Min height (see snapshot below) and I need to return the average minimum and maximum height for all pokemon in the form of a tuple
const allPokemon = [
{
Height: {
Minimum: '0.61m',
Maximum: '0.79m',
},
},
];
I need to use HOFs so I was thinking to do something like this for both Maximum and Minimum height:
allPokemon.reduce((acc, cur) => acc + parseInt(cur.Height.Maximum), 0) / allPokemon.length;
allPokemon.reduce((acc, cur) => acc + parseInt(cur.Height.Minimum), 0) / allPokemon.length;
but I'm not sure how to return the two values in the form of a tuple (create empty array and push the values in? Concat method?)
Any help would be much appreciated.
question from:
https://stackoverflow.com/questions/65842847/returning-a-tuple-in-javascript 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…