type DataItem = { [ key ] : number ; } ; const getDataItemMaxValue = ( dataItem ) => Math . max ( ... Object . values ( dataItem ) ) ; const getDataMaxValue = ( data ) => data . reduce ( ( acc , dataItem ) => Math . max ( acc , getDataItemMaxValue ( dataItem ) ) , 0 ) ; const findTopDomain = ( data ) => { const maxValue = getDataMaxValue ( data ) ; const base10 = Math . floor ( Math . log10 ( maxValue ) ) ; const roundedMaxValue = Math . pow ( 10 , base10 ) ; const topDomain = roundedMaxValue * Math . ceil ( maxValue / roundedMaxValue ) ; return Math . max ( topDomain , 10 ) ; } ; export default findTopDomain ;