Hello, Construct friends! I need help coming up with a method for abbreviating consecutive tokens in a string with redundant information in a specific way.
Outlined below are a few examples of the results that I'm trying to achieve.
Example 1:
input = "Day 1: Routine A|Day 2: Routine A|Day 3: Routine A|Day 4: Routine A"
output = "Day 1–4: Routine A"
Example 2:
input = "Day 1: Routine A|Day 2: Routine A|Day 3: Routine B|Day 4: Routine B"
output = "Day 1–2: Routine A|Day 3–4: Routine B"|
Example 3:
input = "Day 1: Routine A|Day 2: Routine A|Day 3: Routine B|Day 4: Routine A"
output = "Day 1–2: Routine A|Day 3: Routine B|Day 4: Routine A"
Example 4:
input = "Day 1: Routine A|Day 2: Routine B|Day 3: Routine B|Day 4: Routine A"
output = "Day 1: Routine A|Day 2–3: Routine B|Day 4: Routine A"
Any help would be greatly appreciated!