Say you have an array of integer values, for example, pages of a document or years when something happened, like years when new Delphi version was released:
delphiReleased: TArray<integer> = [1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2005, 2006, 2007, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2020, 2021, 2022];
If you would want to display the above years in a user friendly manner as a set of ranges, you could go for:
1995 - 1999, 2001 - 2003, 2005 - 2007, 2009 - 2018, 2020 - 2022
Here’s an algorithm (in a console app code) that does the above
Continue reading