JSON array of objects with properties “from” and “to” and group it by time period

Create a function that creates a string description based on input. Function should take a JSON array of objects with properties “from” and “to” and group it by time period. In case if dates in the array are intersect then your function should combine them in one period, else periods should be separated.

test cases for better understanding of the task

[
  {
    "from":"03/01/2021",
    "to":"03/06/2021"
  },
  {
    "from":"03/10/2021",
    "to":"03/15/2021"
  },
  {
    "from":"03/20/2021",
    "to":"03/25/2021"
  }
]

Output: Mar 1-6, 10-15, 20-25

[
  {
    "from":"03/01/2021",
    "to":"03/05/2021"
  },
  {
    "from":"03/08/2021",
    "to":"03/10/2021"
  },
  {
    "from":"03/07/2021",
    "to":"03/20/2021"
  }
]

Output: Mar 1-5, 7-20

[
  {
    "from":"03/01/2021",
    "to":"03/05/2021"
  },
  {
    "from":"03/04/2021",
    "to":"03/10/2021"
  },
  {
    "from":"03/07/2021",
    "to":"03/20/2021"
  },
  {
    "from":"03/20/2021",
    "to":"03/30/2021"
  }
]

Output: Mar 1-30

[
  {
    "from":"03/01/2021",
    "to":"03/05/2021"
  },
  {
    "from":"03/06/2021",
    "to":"03/08/2021"
  },
  {
    "from":"03/15/2021",
    "to":"03/18/2021"
  },
  {
    "from":"03/16/2021",
    "to":"03/28/2021"
  }
]

Output: Mar 1-8, 15-28

For now, here is the code

const data = [ { "from":"03/01/2021", "to":"03/06/2021" }, { "from":"03/10/2021", "to":"03/15/2021" }, { "from":"03/20/2021", "to":"03/25/2021" } ]

const monthToString = month => {
  const months = {
    '01': 'Jan',
    '02': 'Feb',
    '03': 'Mar',
    '04': 'Apr',
    '05': 'May',
    '06': 'Jun',
    '07': 'Jul',
    '08': 'Aug',
    '09': 'Sep',
    '10': 'Oct',
    '11': 'Nov',
    '12': 'Dec',
    
  }
  return months[month] || month
}


const result = Object.entries(data.reduce((res, {from, to}) => {
  const [monthFrom, day, year] = from.split('/')
  const [m, dayTo, y] = to.split('/')
  
  const month = monthToString(m)
  
  return {
   ...res,
   [month]: [...(res[month] || []), [day, dayTo]]
  }
  
}, {})).map(([month, days]) => `${month} ${days.map(([from, to]) => `${parseInt(from)}-${parseInt(to)}`).join(', ')}`).join('\n')

console.log(result)

Can some help? Learning JS…little bit hard for me(