Write a C# function called FormatIntegers that takes an enumerable of integers as input,…
- User
Write a C# function called FormatIntegers that takes an enumerable of integers as input, and converts each range of consecutive integers into a sorted string representation. The string representation should include the start and end of each range, separated by a hyphen, and ranges should be separated by commas. If an integer appears multiple times in the input, it should only appear once in the output string. The function should also remove any trailing comma and space from the output string. Here is an example of the desired input and output:
Input: {5, 7, 8, 9, 10, 10, 15, 16, 17, 18, 20}
Output: 5, 7-10, 15-18, 20
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.