Analysing an array of objects data using my function and Math.max