Summarizing a list of Channels

Heres the problem I have:

Turn this string input: “Ch 471: PRO BM R #5,Ch 472: PRO BM R #4,Ch 473: PRO BM R #3,Ch 481: PRO BM L #5,Ch 482: PRO BM L #4,Ch 484: PRO BM L #3”

Into this string output:
Ch 471-473: PRO BM R #3-5
Ch 481-484: PRO BM L #3-5

Im attempting to write a function in JavaScript that essentially filters through a string of channels separated by commas of x amounts and then summarizes them in the format above. In the example above there are 6 different channels with positions and units.

The deciding/grouping factor are the positions (In the above example, PRO BM R and PRO BM L) – So finding all the channels and units on one position and then summarizing that info.

Heres details on nomenclature:

  • Channels = Ch 471
  • Positions = PRO BM R
  • Units = #5

What I have tried so far, and what Im assuming I would need to do is use several loops to split() the data

  • First by comma
  • Then by :
  • Then by # sign

Then push the data into 3 different arrays

  1. Channel Array
  2. Position Array
  3. Unit Array

Then filter through each array to find unique values, max values, etc. I just can’t wrap my head around this problem though?

Any pointers, example code, or assistance of any kind is welcomed!