Thursday, July 19, 2012

Combine Ranges of Integers

At one point in an application I needed to be able to combine a range of numbers into a comma-delimited string of ints with the fun added twist of combining all sequential ints together into a range.  Stupid exact matching tool spec.... So instead of writing a new tool to do the same validation check (because I'm crazy but also the other *azy: lazy) I wrote a method to create the combined ranges.

This is in Groovy and quite frankly may be able to be more efficient, but this is what I pounded out that's quick to solve this problem.  Improve if you want!


If you find improvements, feel free to post, all I ask is to please make sure you've tested your code before posting.  Nothing is sadder than getting someone's code from online and then having to debug.  Though it's the easiest thing to blame in your work ;)

</sidebar>


No comments:

Post a Comment